I am struggling with this issue. I have an azure-pipelines.yml
which is set to build a python artifact in three different ways- one upon merge to master
(1.0.x), to develop
(0.5.xrc) and otherwise just a dev artifact (0.3.x.dev0), x being the incremental number.
I understand that the build needs to increment upon a pull-request update, and it produces an artifact with version 0.3.x.dev0 which is expected. However upon merge, it triggers the build of the prod or rc version (1.0.x or 0.5.xrc), but then it also automatically runs another pipeline to build a dev artifact.
My question is, how do I remove the duplicate build upon merge to develop
or master
? This is presumably to do with a PR update trigger upon merge. I added the autoCancel
functionality but that does not seem to have helped.
trigger:
branches:
include:
- develop
- master
pr:
branches:
include:
- develop
- master
autoCancel: true
variables:
initialVersion: '1.0.0'
buildCounter: $[counter(variables['initialVersion'], 0)]
pool:
vmImage: ubuntu-latest
strategy:
matrix:
Python310:
python.version: '3.10'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
# Increment the version based on prod release
- script: |
set -e
if [[ "$(Build.SourceBranch)" == "refs/heads/master" ]]; then
echo "1.0.10" > VERSION.txt
elif [[ "$(Build.SourceBranch)" == "refs/heads/develop" ]]; then
echo "0.5.$(buildCounter)rc" > VERSION.txt
else
echo "0.3.$(buildCounter).dev0" > VERSION.txt
fi
displayName: 'Set Version based on Branch'
- script: |
set -e
version=$(cat VERSION.txt)
echo "##vso[build.updatebuildnumber]$version"
displayName: 'Update Build Number'
- script: |
set -e
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m unittest discover -v
python setup.py sdist bdist_wheel
displayName: 'Install dependencies, run unit tests, build and create artifact'
- task: ArchiveFiles@2
displayName: "Archive files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build.zip"
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build.zip'
publishLocation: 'Container'
artifactName: 'artifact-name'
3
Answers
I can reproduce the similar issue when using Bitbucket .
The cause of this issue could be that the WEBHOOKs of Repo Resource are mixed on Bitbucket.
You can refer to the following steps to re-create the Webhook and check if it can work.
Step1: Navigate to Bitbucket repo setting -> Webhooks and remove all Repository hooks related to Azure DevOps.
Step2: Navigate to Azure Devops YAML Pipeline -> Triggers Option -> Trigger tab . Click the restore option, it will automatically create new webhook in Bitbucket Webhook
If you are using Github Repo, you can also check the webhook in repo resource and recreate the webhook in Azure DevOps.
If you are using branch policies to protect these branches and only push new changes to the
develop
andmaster
using PR’s, then I am assuming you do not actively need the CI trigger for this pipeline.You get the duplicate runs because first it triggers a build for the PR, and once the PR gets merged to
develop
/master
, it will hit the CI trigger defined intrigger
.Suggestion #1
So to stop the duplicate build upon merge, you could simply add
trigger: none
.Like mentioned, that is assuming you are looking only to get new changes into
develop
andmaster
branches using PR and build validation from PR.Suggestion #2
If I am on the other hand assuming you are less restrictive towards the
develop
branch, meaning we do not protect it from direct pushes using branch policies, while we want PR’s before we merge new code tomaster
, then my setup would look like this:Suggestion #3
You can also add build validations using branch policies:
Maybe I misunderstood what you are actually looking for, but let me know!