Search code examples
azure-devopscontinuous-integrationazure-pipelinescontinuous-deployment

Azure DevOps: Create Build Policy for all pull requests


I am attempting to create a build policy for all pull requests I make for an Azure DevOps Repository. The problem is that the branch policies only target specific branches. The project contains many user story branches - and task branches for each user story branch, which need to get merged into their associated user story branch when completed. When merging the user story branches into dev, they get deleted. It would be tedious to constantly create build policies for branches that get removed on completion.

I was wondering if there was a method to create a build policy that applies to all pull requests in a given repository?

Example: Finished work on branch task-1 whose branch structure is like so: dev/user-story-1/task-1. I want the policy to apply to user-story-1 branch when it is created, so when I merge task-1 -> user-story-1, the build validation pipeline runs and succeeds before it can be merged. This way, when additional user story branches get created, build policies do not have to be added to each one.

I attempted using wildcards with a YAML pipeline, however though the build triggers on every pull request, there is nothing enforcing it to pass when merging into the parent branch.


Solution

  • I was wondering if there was a method to create a build policy that applies to all pull requests in a given repository?

    For a given repository, you can create the build policy on folder level, it will automatically apply to sub branches.

    Sample below, the branch policies applies to any branched created with structure userstory/*, like userstory/user-story-1, userstory/user-story-2...etc.

    enter image description here

    enter image description here

    If you create build policy on All Repositories level, the branch policy will apply to all repositories, please check similar link here. but the pattern * only used with format /*, cannot use like user-story-*.

    In addition, for your expectation below:

    When merging the user story branches into dev, they get deleted.

    if the userstory/user-story-* has a policy, you cannot directly delete it after pull request complete as screenshot below. You can grant Bypass policies when pushing permission the repository, then you can delete the branch.

    enter image description here