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 ?
2
Answers
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
*
orfeature/*
.In general I’m able to cover almost all of my branches in 2 or 3 policies.
main
,develop
andfeature/*
.A good naming convention can do wonders in this case.
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.