需求
因此,Azure DevOps中有一些新功能,该功能允许管道触发其他管道,并记录在这里:https : //docs.microsoft.com/zh-cn/azure/devops/pipelines/build/triggers?view=azure- devops&tabs = yaml#pipeline-triggers-1听起来不错,但事实是我无法获得所需的行为。我想要在同一存储库中的2个管道:
管道A语法
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:
...
当前行为
管道A不会由其他任何管道触发,而只能在对其自己的存储库进行更改时触发。由于无论如何都会对其自己的存储库进行更改,因此它会陷入无尽的循环。
问题/评论
发现
trigger: none
到流水线的顶部A阻止了它在对存储库进行提交时运行,只是目前根本不运行!az pipelines run --branch master --name "<PipelineName>" --org "https://dev.azure.com/<OrganisationName>" -p "<ProjectName>"
工作方案
因为所有构建都集中在一个管道模板中,所以我更改了该模板,以在成功发布工件时触发管道A。这是流水线触发代码,几乎是逐字记录的(https://docs.microsoft.com/zh-cn/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops)从最后几个步骤开始:
# 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
注意事项
<YourPipelineName>
进行适当的更改,您的分支名称处理将与我的有所不同本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句