Requirement
So, there is some newish functionality in Azure DevOps which allows pipelines to trigger other pipelines and is documented here: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml#pipeline-triggers-1 It sounds great, apart from the fact I can't get the behaviour I need. I want 2 pipelines in the same repository:
Pipeline A Syntax
resources:
pipelines:
- pipeline: database
source: database
trigger:
branches:
- develop
- release/*
# The stages filter should work, according to: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml
# However, this error occurs when specifying: /azure-pipelines.yml (Line: 8, Col: 15): Stage filters in pipeline resource database is not supported.
#stages:
#- Build
- pipeline: auth
source: auth
trigger:
branches:
- develop
- release/*
- pipeline: api
source: api
trigger:
branches:
- develop
- release/*
- pipeline: web
source: web
trigger:
branches:
- develop
- release/*
... multiple triggers - 9 in total
stages:
...
Current Behaviour
Pipeline A is not triggered by any of the other pipelines, but only on changes to its own repo. Since it makes changes to its own repo anyway, it triggers itself in an endless loop.
Questions / Comments
Discovery
trigger: none
to the top of the pipeline A prevented it from running when commits were made to its repo, it just doesn't run at all currently!az pipelines run --branch master --name "<PipelineName>" --org "https://dev.azure.com/<OrganisationName>" -p "<ProjectName>"
If the triggering pipeline and the triggered pipeline use the same repository, both pipelines will run using the same commit when one triggers the other. This is helpful if your first pipeline builds the code and the second pipeline tests it.
Yes, you can have multiple . yml files with any name really. When you create the build pipeline, you pick and reference the existing yaml.
Navigate to Pipelines | Pipelines and select PartsUnlimited-CI build pipeline. Click on Run Pipeline then select Run to trigger the pipeline.
To force a pipeline to run even when there are no code changes, you can use the always keyword. Scheduled builds aren't supported in YAML syntax in this version of Azure DevOps Server. After you create your YAML build pipeline, you can use pipeline settings to specify a scheduled trigger.
Working Solution
Because all of my builds are centralised in one pipeline template, I changed this template to trigger my pipeline A on successful publishing of an artifact. Here's the pipeline trigger code which is pretty much verbatim from (https://docs.microsoft.com/en-us/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops), apart from the last couple of steps:
# Updating the python version available on the linux agent
- task: UsePythonVersion@0
displayName: Upgrade build agent Python version
inputs:
versionSpec: '3.x'
architecture: 'x64'
# Updating pip to latest
- script: python -m pip install --upgrade pip
displayName: 'Upgrade pip'
# Updating to latest Azure CLI version.
- script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
displayName: 'Upgrade azure cli'
- script: az --version
displayName: 'Show Azure CLI version'
- script: az extension add -n azure-devops
displayName: 'Install Azure DevOps Extension'
- script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
env:
AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
displayName: 'Login Azure DevOps Extension'
- script: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project="$(System.TeamProject)" --use-git-aliases true
displayName: 'Set default Azure DevOps organization and project'
- script: |
set -euo pipefail
if [[ "$(Build.SourceBranch)" == *"/release/"* ]]; then
branchName="master"
else
branchName="develop"
fi
commandLine="--branch $branchName --name <YourPipelineName>"
echo "Triggering release creation with: az pipelines run $commandLine"
az pipelines run $commandLine
displayName: Trigger release build for internal (develop) and external (release) builds
Caveats
<YourPipelineName>
as appropriate, and your branch name handling is going to be different to mineIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With