Reputation: 188
I have created a pipeline in my repository which is used to validate code by executing unit tests for code that is being pushed to features/*
branches. The same pipeline is used as Build validation pipeline set as Branch Policy on the develop branch to validate incoming PRs. This is the trigger of the pipeline.
# pipeline.yml
trigger:
batch: false
branches:
include:
- features/*
However we have come across the following condition: Given an open PR from refs/heads/features/azure-pipelines -> refs/heads/develop
we push a commit on the features/azure-pipelines
branch.
This causes the pipeline to trigger twice. To my understanding one of the runs is due to the trigger of the pipeline (The one marked as Individual CI on the screenshot) and the second run is due to branch policy trying to validate code being pushed onto the open PR to develop. (The PR Automated)
Is there any way to disable one of the executions since it's essentially a duplicate? I was maybe looking for a way to retrieve open PRs and abort execution of a pipeline for Individual CI
if there is an open PR for a branch but I am not sure that's the best way around that and I am looking for options.
Upvotes: 7
Views: 5930
Reputation: 4681
trigger:
- main #name of your default branch
The YAML build templates included with Azure Pipelines were configured to trigger builds for any branch within a repository. This included pull request topic branches. As a result, two builds were triggered when pull requests were created. One build for the pull request branch in response to the continuous integration trigger, and a second build for the pull request branch in response to the pull request trigger.
By using the YAML snippet below, the built-in YAML templates will be configured to trigger a continuous integration build only for the master branch. New pull requests will still build using the pull request trigger. For more details, see the documentation for build pipeline triggers .
Upvotes: 1
Reputation: 21
To disable the automatic pipeline run for changes in a pull request, go to Repos > Branches, then on the source branch, click the vertical ... , select Branch policies, and then in the Build Validation option, disable the 'Validate code by pre-merging and building pull request changes' option.
Upvotes: 0
Reputation: 213
I had the same problem. To prevent this, in your trigger.branches.include
you only need to put the build branches, not the branches used in pull requests (like features/*
).
# pipelines.yml
trigger:
batch: false
branches:
include:
- master
- dev
stages:
- stage: test
jobs:
template: unit-test-jobs.yml
- stage: deploy
condition: ne(variables['Build.Reason'], 'PullRequest')
jobs: ...
This way, your pipeline will run due pull requests and when new commits are pushed to your branches (master
and dev
in the example above).
Upvotes: 1
Reputation: 141
You can set
trigger: none
This way only the branch policy will trigger the pipeline.
Upvotes: 2
Reputation: 76700
Is there any way to disable one of the executions since it's essentially a duplicate?
As we know, we could not disable the Build validation pipeline set as Branch Policy on the develop branch to validate incoming PRs unless we cancel the Build validation.
For your situation, you could try to include [skip ci]
in the commit message or description of the HEAD commit to make the Azure Pipelines skip running CI when you plan to merge the features branch to the develop branch.
You could check the document Skipping CI for individual commits for some more details.
Upvotes: 3
Reputation: 40583
Here it depends if they does the same. You can have conditional checks in the pipeline which does a different things for PR and CI runs. However, I'm pretty sure that this is not possible, because one is defined on the YAML and the second on the Azure DevOps portal. So even if you disnle PR trigger here in YAML, a branch policy still runs a PR. And you can specify antyhing in YAML to block branch policy.
Upvotes: 0