不支持触发块中的变量。有关更多信息,请参阅此处的文档。
触发器块不能包含变量或模板表达式。
如果您不希望管道被其他分支触发,您可以尝试以下解决方法。
创建一个额外的管道来检查源分支是否匹配 release/major_minor_patch。并在这个附加管道中触发主管道。
variables:
major: 2020
minor: 3
patch: 1
triggerMain: false
trigger:
branches:
include:
- releases/*
steps:
- powershell: |
$branch = "$(Build.SourceBranchName)"
if ($branch -match "$(major).$(minor).$(patch)") {
echo "##vso[task.setvariable variable=triggerMain]True" #set variable triggerMain to true if matches.
}
- task: TriggerBuild@3
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: '56' #{id of your main pipeline}
queueBuildForUserThatTriggeredBuild: true
ignoreSslCertificateErrors: false
useSameSourceVersion: true
useSameBranch: true
waitForQueuedBuildsToFinish: false
storeInEnvironmentVariable: false
authenticationMethod: 'Personal Access Token'
password: '$(system.accesstoken)'
enableBuildInQueueCondition: false
dependentOnSuccessfulBuildCondition: false
dependentOnFailedBuildCondition: false
checkbuildsoncurrentbranch: false
failTaskIfConditionsAreNotFulfilled: false
condition: eq(variables['triggerMain'], 'True')
在上述管道中。它将首先被触发以检查源分支是否与农场匹配。如果匹配,则将执行任务 TriggerBuild 以触发主管道。