要求
因此,Azure DevOps中有一些新功能,该功能允许管道触发其他管道,并记录在这里:https://docs.microsoft.com/en-us/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
会阻止它在对存储库进行提交时运行,只是目前根本没有运行!az pipelines run --branch master --name "<PipelineName>" --org "https://dev.azure.com/<OrganisationName>" -p "<ProjectName>"
答案 0 :(得分:5)
工作解决方案
因为所有构建都集中在一个管道模板中,所以我更改了该模板,以在成功发布工件时触发我的管道A。这是流水线触发代码,它与(https://docs.microsoft.com/en-us/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>
,您的分支名称处理将与我的不同答案 1 :(得分:1)
我遇到了同样的问题。 我在这里找到了解决方案: https://developercommunity.visualstudio.com/content/problem/864701/pipeline-trigger-not-working-as-expressed-in-docum.html?childToView=897210#comment-897210
在快捷方式中,当我将依赖管道中的defaultBranch更改为工作分支时 触发开始工作。: 您需要进入:
Edit -> Triggers (3 dots in right upper corner) -> YAML -> Get sources -> Default branch for manual and scheduled builds
答案 2 :(得分:0)
如果您不是从触发管道发布工件,那么它将不会触发被触发的管道。我已经创建了一个可行的最低可行产品,并在此answer中解释了该过程。