AWS Codebuild createProject方法缺少Github auth的oauth令牌参数?

问题描述 投票:2回答:2

AWS Codebuild createProject方法缺少Github身份验证的OAuth令牌参数?

我想避免使用CodePipeline。我想以编程方式使用Github令牌创建代码构建项目,但我似乎找不到包含GitHub令牌的方法。有没有人经历过这个?

var params = {
    artifacts: {
      /* required */
      type: 'S3',
      location: 'STRING_VALUE',
      packaging: 'ZIP'
    },
    environment: {
      /* required */
      computeType: 'BUILD_GENERAL1_LARGE',
      image: 'aws/codebuild/nodejs:4.3.2', /* required */
      type: "LINUX_CONTAINER",
    },
    name: key, /* required */
    source: {
      /* required */
      type: "GITHUB",
      auth: {
        type: "OAUTH"
      },
      buildspec: 'echo "test";',
      location: `https://github.com/${original.organizations.name}/${original.repos.name}.git`,

    },
    description: 'STRING_VALUE',
    serviceRole: 'arn:aws:iam::171566796811:role/tmmmm6',
    timeoutInMinutes: 5
  };
  codebuild.createProject(params, function (err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response


    console.log("WEBHOOK")
    var params = {
      projectName: key /* required */
    };
    codebuild.createWebhook(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });


  });

我尝试使用以下URL格式:https://${original.github.token}:@github.com/${original.organizations.name}/${original.repos.name}.git,但这不起作用。 Codebuild不允许我创建webhook。

这是文档。 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeBuild.html是否可以使用GitHub访问令牌创建代码构建?我知道如何使用代码管道,但我想尽可能避免使用代码管道。

amazon-web-services github aws-codebuild
2个回答
4
投票

没有程序化的方法来做到这一点。您可以使用AWS CodeBuild控制台连接您的GitHub帐户。这是一次性设置。连接后,使用GitHub帐户中的源的所有未来CodeBuild项目都将能够使用存储的令牌。


1
投票

您缺少模板中的参数。源应如下所示:

    source: {
      /* required */
      type: "GITHUB",
      auth: {
        type: "OAUTH",
        resource: "GITHUB"
      },
      buildspec: 'echo "test";',
      location: `https://github.com/${original.organizations.name}/${original.repos.name}.git`,

    },

正如Zhen Li所说,您必须首先通过控制台(create auth resource like this)向Github授权您的AWS账户,然后您可以根据需要以编程方式为您的Github创建任意数量的授权构建项目!

© www.soinside.com 2019 - 2024. All rights reserved.