git AWS CodePipeline 可以跟踪多个功能分支并在每个分支上运行测试吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46696036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:55:49  来源:igfitidea点击:

Can AWS CodePipeline track multiple feature branches and run tests on each?

gitamazon-web-servicescontinuous-integration

提问by aidan.plenert.macdonald

With Bitbucket and Bamboo, I was able to have Bamboo track every feature branch and run tests on each so that, at the pull request time, I was able to see if the branch passed its unit tests.

使用 Bitbucket 和 Bamboo,我能够让 Bamboo 跟踪每个功能分支并在每个分支上运行测试,以便在拉取请求时,我能够查看分支是否通过了单元测试。

With AWS CodePipeline, I can't tell if I am able to track each feature branch and have tests run on them before merging.

使用AWS CodePipeline,我无法确定是否能够跟踪每个功能分支并在合并之前对它们运行测试。

Is this possible? If so, please point me to documentation.

这可能吗?如果是这样,请指出我的文档。

采纳答案by matthewcummings516

Unfortunately, it does not appear possible to trigger builds off of multiple branches in CodePipeline natively. It's a bit of a surprise to me as every other CI tool I've used offers this functionality right out of the box (GitLabCI, TravisCI, CircleCI, Bitbucket Pipelines, TeamCity) or with a battle tested plugin (Jenkins).

不幸的是,似乎不可能在本地触发 CodePipeline 中多个分支的构建。这让我有点惊讶,因为我使用过的所有其他 CI 工具都提供了开箱即用的功能(GitLabCI、TravisCI、CircleCI、Bitbucket Pipelines、TeamCity)或带有经过实战测试的插件 (Jenkins)。

However, there are probably multiple ways to work around this limitation for now, this is one that I found and may use/adapt: https://github.com/nicolai86/awesome-codepipeline-ci

但是,目前可能有多种方法可以解决此限制,这是我发现的并且可以使用/改编的方法:https: //github.com/nicolai86/awesome-codepipeline-ci

I have this same exact problem, I'm working on it now. :)

我有同样的问题,我现在正在处理它。:)

回答by Brandon

I was looking for a solution to exactly this problem. Eventually I settled on having a CodeBuild, which can be triggered off of a branch regex, begin the pipeline by pushing an archive to a specific S3 key. In my case, I also had that CodeBuild do my full build/test process, but you could also configure the CodeBuild to only pull the code and push it the the S3 key that triggers your CodePipeline.

我正在寻找解决这个问题的方法。最终我决定使用 CodeBuild,它可以从分支正则表达式触发,通过将存档推送到特定的 S3 键来开始管道。就我而言,我也让 CodeBuild 执行我的完整构建/测试过程,但您也可以将 CodeBuild 配置为仅拉取代码并将其推送到触发 CodePipeline 的 S3 密钥。

Here's part of an example CodeBuild config matching 2 branches: Example showing a <code>Branch filter</code>matching 2 branches

这是匹配 2 个分支的示例 CodeBuild 配置的一部分: 显示匹配 2 个分支的 <code>Branch filter</code>的示例

Then I set the CodeBuild artifact to go to a single key in a single bucket.

然后我将 CodeBuild 工件设置为转到单个存储桶中的单个键。

Then I setup a CodePipeline with an Amazon S3 source pointing to the same key/bucket.

然后我设置了一个 CodePipeline,其 Amazon S3 源指向同一个密钥/存储桶。

回答by aidan.plenert.macdonald

Further review shows that with Cloudformation, you can pick the branch that CodePipeline tracks,

进一步表明,使用 Cloudformation,您可以选择CodePipeline 跟踪的分支,

AWS CodeCommit (CodeCommit)

  • PollForSourceChanges1 (Optional)
  • RepositoryName (Required)
  • BranchName (Required)

AWS 代码提交 ( CodeCommit)

  • PollForSourceChanges1(可选)
  • 存储库名称(必填)
  • 分支名称(必填)

You can see an example of complete templatebut the CodePipeline stage looks like,

您可以看到完整模板的示例,但 CodePipeline 阶段看起来像,

Name: CheckoutSourceTemplate
ActionTypeId:
  Category: Source
  Owner: AWS
  Version: 1
  Provider: CodeCommit
Configuration:
  PollForSourceChanges: True
  RepositoryName: !GetAtt [PipelineRepo, Name]
  BranchName: master
OutputArtifacts:
  - Name: TemplateSource
RunOrder: 1

With CodeCommit Repo's, you can create Triggersthat can use these triggers to launch a Lambda function,

随着CodeCommit回购的,你可以创建触发器,可以使用这些触发器来启动一个lambda函数

You can configure Lambda functions by creating the trigger in the Lambda console as part of the function. This is the simplest method, as triggers created in the Lambda console automatically include the permissions required for AWS CodeCommit to invoke the Lambda function. If you create the trigger in AWS CodeCommit, you must include a policy to allow AWS CodeCommit to invoke the function. For more information, see Create a Trigger for an Existing Lambda Functionand Example 2: Create a Policy for AWS Lambda Integration.

您可以通过在 Lambda 控制台中创建触发器作为函数的一部分来配置 Lambda 函数。这是最简单的方法,因为在 Lambda 控制台中创建的触发器会自动包含 AWS CodeCommit 调用 Lambda 函数所需的权限。如果您在 AWS CodeCommit 中创建触发器,则必须包含一个策略以允许 AWS CodeCommit 调用该函数。有关更多信息,请参阅为现有 Lambda 函数创建触发器示例 2:为 AWS Lambda 集成创建策略

So what could happen is to set up a CloudFormation template like above to track the master branch. Then have CodeCommit trigger on repository changes and call a Lambda function that uses Boto3 to get_pipelineto retrieve the master branch pipeline.

所以可能发生的事情是设置一个像上面一样的 CloudFormation 模板来跟踪主分支。然后让 CodeCommit 在存储库更改时触发,并调用使用 Boto3 的 Lambda 函数get_pipeline来检索主分支管道。

Then using either update_pipelineor create_pipelineto add a stage to the existing master branch pipeline or create an entirely new pipeline that tracks the additional branches desired.

然后使用update_pipelinecreate_pipeline将一个阶段添加到现有的主分支管道或创建一个全新的管道来跟踪所需的其他分支。

This way, the CodePipeline can track the feature branches in a useful way.

这样,CodePipeline 可以有用的方式跟踪功能分支。