如何在Azure DevOps中自动触发拉取请求(PR)构建管道?

huangapple go评论73阅读模式
英文:

How to automatically trigger pipeline on PR build in Azure DevOps?

问题

我是Azure DevOps的新手,我试图在那里模仿GitHub Actions的一些高级行为。在我的存储库中,我使用以下的build.yaml来触发一个流水线,每当对主分支进行推送时:

trigger:
  branches:
    include:
    - main

现在,我想要每次向主分支提出PR时都触发相同的流水线,以便在合并之前检查其有效性。根据文档,应该在每个分支上手动完成此操作,使用分支策略](https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#pr-triggers) 这在扩展时并不具备可扩展性。是否有一种自动化的方法?或者是否有一个分支创建设置,可以确保所有分支都具有相同的策略?

英文:

I'm new to Azure DevOps and I try to mimic some fancy behaviors of Github actions there. In my repository I use the following build.yaml to trigger a pipeline whenever a push is made to the main branch:

trigger:
  branches:
    include:
    - main

Now I would like every PR made to main to trigger the same pipeline in order to check the validity before merging. According to the doc this should be done manually on each branch using branch policy which is not scalable at all. Is there a way to make it automatic ? or maybe a branch creation setting that ensure all branches have the same policy ?

答案1

得分: 1

管道将自动触发。如果您希望在管道失败时阻止 PR,请使用分支策略。幸运的是,您可以在策略配置中使用通配符。因此,您可以将策略设置为 *feature/*

通常情况下,我可以用2或3个策略覆盖几乎所有的分支。maindevelopfeature/*

在这种情况下,良好的命名约定可以发挥奇效。

英文:

The pipeline will trigger automatically. If you need the PR to block in case the pipeline fails, you need a Branch Policy. Luckily, you can use wildcards in the policy configuration. So, you can set the policy to * or feature/*.

如何在Azure DevOps中自动触发拉取请求(PR)构建管道?

In general I'm able to cover almost all of my branches in 2 or 3 policies. main, develop and feature/*.

A good naming convention can do wonders in this case.

答案2

得分: 1

为了详细说明@jessehouwing的答案,因为这只提供了初始设置。您还需要添加构建验证部分,以便在提交PR时启动build.yml文件。

答案将保护所有主分支;但是,您很可能需要在每个仓库上设置特定的构建以启动,这需要在各个仓库级别进行设置。

如何在Azure DevOps中自动触发拉取请求(PR)构建管道?

英文:

To elaborate on @jessehouwing's answer as this only provides the initial setup. You will also want to add your build validation piece to have the build.yml file kick off when your PR is submitted.

The answer will protect all main branches; however, you are most likely going to have specific builds kick off on each repository which will need to be set at the individual repo level.

如何在Azure DevOps中自动触发拉取请求(PR)构建管道?

huangapple
  • 本文由 发表于 2023年7月3日 15:18:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定