can the build policies on a pull request in azure devops use the yaml-files that are updated in said pr?

Create a separate yaml pipeline with the pre merge build steps that you then set in the PR policies for. It will always run the code from the current branch that the PR is created from.

We do it like this: (All in same repo)

  1. build_steps.yml – Yaml template with build steps
  2. azure-pipelines-yml – Main pipeline that has a reference to build_steps.yml to build the project
  3. pre_merge.yml – Secondary pipeline that is run only by PR request which has a reference to build_steps.yml so there are no differences in the build and two places to update if something changes.

Whole yaml definition:

trigger: none #Pipeline should never trigger on any branches. Only invoked by the policy.

  - name: system.buildConfiguration 
    value: 'Release'

  - name: system.buildPlatform
    value: 'win10-x86'

  - name: system.debug
    value: 'false'

  vmImage: 'windows-latest'

name: $(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r)

- template: build_steps.yml

And then in the policies you setup it like this: enter image description here

All this applies also to classic pipelines. You need to create a seperate pre-merge build pipeline that could reference a TaskGroup with the steps used in the main build pipeline. In both cases you dont have to use a template or Taskgroup and and create the steps manually. But if the build would change in the future you have 2 places to update.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top