简体   繁体   English

AWS CodePipeline 能否跟踪多个功能分支并在每个分支上运行测试?

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

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.如果是这样,请指出文档。

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.如果是这样,请指出我的文档。

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.最终我决定使用 CodeBuild,它可以从分支正则表达式触发,通过将存档推送到特定的 S3 键来开始管道。 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 执行我的完整构建/测试过程,但您也可以将 CodeBuild 配置为仅拉取代码并将其推送到触发 CodePipeline 的 S3 密钥。

Here's part of an example CodeBuild config 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 源指向相同的密钥/存储桶。

CodePipeline is not the right tool for you. CodePipeline 不是适合您的工具。 Create a separate, standalone CodeBuild project.创建一个单独的、独立的 CodeBuild 项目。 It will work very much like other 3rd party CI services such as Travis.它将与 Travis 等其他 3rd 方 CI 服务非常相似。

Make sure to select the "Rebuild every time a code change is pushed to this repository" Source setting.确保选择“每次将代码更改推送到此存储库时重新构建”源设置。 This will trigger a build from push to any branch and also from other web hook events eg.这将触发从推送到任何分支以及其他网络钩子事件的构建,例如。 created PRs.创建了 PR。 You can also create filters to manage them.您还可以创建过滤器来管理它们。

There are a number of ways you can connect this "CI stage" to a continuous delivery pipeline, which is what CodePipeline is for:您可以通过多种方式将此“CI 阶段”连接到持续交付管道,这就是 CodePipeline 的用途:

  1. The simplest is just to use CodeBuild as a gate for pushing changes to the pipeline source branch, typically master.最简单的方法是使用 CodeBuild 作为将更改推送到管道源分支(通常是 master)的门。
  2. You can also push artifacts created in CodeBuild to ECR or S3 and trigger a pipeline from those events.您还可以将在 CodeBuild 中创建的工件推送到 ECR 或 S3,并从这些事件触发管道。
  3. If you want to get complicated, use some other jiggery pokery eg.如果您想变得复杂,请使用其他一些jiggery pokery,例如。 SQS and Lambda. SQS 和 Lambda。

I had the same confusion as CodeBuild and CodePipeline are tightly interlinked but also separate tools.我也有同样的困惑,因为 CodeBuild 和 CodePipeline 是紧密相连的,但也是独立的工具。 CodePipeline does use CodeBuild but each has its own Git connector that works differently. CodePipeline 确实使用 CodeBuild,但每个都有自己的 Git 连接器,其工作方式不同。

Further review shows that with Cloudformation, you can pick the branch that CodePipeline tracks ,进一步审查表明,使用 Cloudformation,您可以选择CodePipeline 跟踪的分支,

AWS CodeCommit ( CodeCommit ) AWS CodeCommit ( CodeCommit )

  • PollForSourceChanges¹ (Optional) PollForSourceChanges¹(可选)
  • RepositoryName (Required)存储库名称(必填)
  • BranchName (Required)分支名称(必填)

You can see an example of complete template but 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 Triggers that 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.您可以通过在 Lambda 控制台中创建触发器作为函数的一部分来配置 Lambda 函数。 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.这是最简单的方法,因为在 Lambda 控制台中创建的触发器会自动包含 AWS CodeCommit 调用 Lambda 函数所需的权限。 If you create the trigger in AWS CodeCommit, you must include a policy to allow AWS CodeCommit to invoke the function.如果您在 AWS CodeCommit 中创建触发器,则必须包含一个策略以允许 AWS CodeCommit 调用该函数。 For more information, see Create a Trigger for an Existing Lambda Function and Example 2: Create a Policy for AWS Lambda Integration .有关更多信息,请参阅为现有 Lambda 函数创建触发器示例 2:为 AWS Lambda 集成创建策略

So what could happen is to set up a CloudFormation template like above to track the master branch.所以可能会发生的是设置一个像上面一样的 CloudFormation 模板来跟踪主分支。 Then have CodeCommit trigger on repository changes and call a Lambda function that uses Boto3 to get_pipeline to retrieve the master branch pipeline.然后让 CodeCommit 在存储库更改时触发并调用 Lambda 函数,该函数使用 Boto3 到get_pipeline来检索主分支管道。

Then using either update_pipeline or create_pipeline to 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 就可以有用的方式跟踪功能分支。

Multiple codebuild projects to build multiple branches, drop your artifacts to s3 and pickup with codepipeline from there.多个代码构建项目来构建多个分支,将您的工件放到 s3 并从那里获取代码管道。

What i'm trying to achieve is: Checkout a different branch under the same codebuild project so as to be able to to a diff check and generate packages for sitecore items.我想要实现的是:在同一个 codebuild 项目下签出不同的分支,以便能够进行差异检查并为 sitecore 项目生成包。 ie release\\branch <=> master => then generate package of latest items only, release\\branch project, then Zip.即 release\\branch <=> master => 然后只生成最新项目的包,release\\branch 项目,然后是 Zip。

I have achieved what you want to do by creating ephemeral pipelines, I have a codebuild that looks for branches on the repo which are not main and is triggered on PR.我已经通过创建临时管道实现了您想做的事情,我有一个代码构建,它在 repo 上查找不是主要分支并且在 PR 上触发的分支。

When that codebuild runs, it extracts the branch name and then creates a brand new code pipeline on the fly using the branch it now knows about, this is done with terraform. When the change is merged to master I then destroy the ephemeral environment and the ephemeral pipeline.当该代码构建运行时,它提取分支名称,然后使用它现在知道的分支动态创建一个全新的代码管道,这是通过 terraform 完成的。当更改合并到 master 时,我然后销毁临时环境和临时管道。

I could not think of a neater solution to creating a multi-branch pipeline.我想不出更简洁的解决方案来创建多分支管道。

Alternatively what can be done is to have a dedicated branch to trigger the pipeline (ex: pipeline branch).或者,可以做的是有一个专用分支来触发管道(例如:管道分支)。 Once you want to test code from a branch, you can change the reference of the pipeline branch to your custom branch (ex: feature-branch) such that the pipeline branch will basically "point" to the latest commit of the custom branch and will trigger the code pipeline execution.一旦你想从一个分支测试代码,你可以将管道分支的引用更改为你的自定义分支(例如:feature-branch),这样管道分支将基本上“指向”自定义分支的最新提交并将触发代码管道执行。

Also what we can do is, by taking this a step further, we can create a custom GitHub action, that will trigger the above branch reference change within Github to fully automate the pipeline trigger based on the developer's need.我们还可以做的是,通过更进一步,我们可以创建一个自定义 GitHub 操作,它将触发 Github 内的上述分支引用更改,以根据开发人员的需要完全自动化管道触发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM