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)
- build_steps.yml – Yaml template with build steps
- azure-pipelines-yml – Main pipeline that has a reference to build_steps.yml to build the project
- 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:
#pre_merge.yml trigger: none #Pipeline should never trigger on any branches. Only invoked by the policy. variables: - name: system.buildConfiguration value: 'Release' - name: system.buildPlatform value: 'win10-x86' - name: system.debug value: 'false' pool: vmImage: 'windows-latest' name: $(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r) steps: - template: build_steps.yml
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.