azure - 当一个管道触发另一个管道时如何获取 customSourceVersion 的值?
问题描述
我是天蓝色管道的新手。我正在使用 Azure devops 管道来触发另一个 devops 管道。管道是用 YAML 模式编写的。
管道 A
- task: TriggerBuild@3
displayName: Trigger Setup Pipeline
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: '111'
queueBuildForUserThatTriggeredBuild: true
ignoreSslCertificateErrors: false
useSameSourceVersion: false
useCustomSourceVersion: true
customSourceVersion: '$(Revision)'
useSameBranch: true
waitForQueuedBuildsToFinish: true
waitForQueuedBuildsToFinishRefreshTime: '60'
failTaskIfBuildsNotSuccessful: true
cancelBuildsIfAnyFails: false
treatPartiallySucceededBuildAsSuccessful: false
downloadBuildArtifacts: false
storeInEnvironmentVariable: false
authenticationMethod: 'OAuth Token'
password: '$(PersonalToken)'
enableBuildInQueueCondition: false
dependentOnSuccessfulBuildCondition: false
dependentOnFailedBuildCondition: false
checkbuildsoncurrentbranch: false
failTaskIfConditionsAreNotFulfilled: false
管道 B
- task: DownloadBuildArtifacts@0
condition: and(succeeded(), eq(variables['WCBuildType'], 'Internal'))
inputs:
buildType: 'specific'
project: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
pipeline: '999'
buildVersionToDownload: 'latestFromBranch' # I want to use '$(Revision)' vaue here
branchName: '$(Build.SourceBranch)'
downloadType: 'single'
artifactName: 'Compiled'
downloadPath: 'Artifact'
displayName: 'Download build artifacts'
我想在管道 B 中使用管道 A 的 $(Revision) 值来下载特定构建版本的工件。我还希望 Pipeline B 的触发器在这两种情况下表现不同:
- 每当用户在他的分支中进行任何提交时,它都应该使用 buildVersionToDownload: latestFromBranch
- 当用户触发管道 A 时,管道 B 被触发并使用 buildVersionToDownload: $(Revision) 下载构建工件。
解决方案
在TriggerBuild@3
任务中添加这一行:
buildParameters: 'Revision: $(Revision)'
它将变量发送到触发的构建。
现在,在 Pipeline B 中,您可以创建if
来检查用户是否进行了提交或触发了管道:
${{ if eq(variables['Build.Reason'], 'IndividualCI') }}:
buildVersionToDownload: 'latestFromBranch'
${{ if ne(variables['Build.Reason'], 'IndividualCI') }}:
buildVersionToDownload: '$(Revision)'
推荐阅读
- java - 使用 GrigBagLayout 在 java 中创建一个简单的设计而不使用 swing
- python - 如何在 Linux 服务器中连接 Python、Oracle 11g 和 cx_Oracle?
- batch-file - 使用批处理脚本将浮点变量的值增加 1
- c# - .Net 领域的动态查询构建器
- unity3d - Unity OnStateExit StateMachineBehaviour 永远不会被调用
- android - 自定义 biometricPrompt
- android - 删除firebase数据库子节点时应用程序崩溃
- nginx - NGINX 使用位置指令拒绝访问文件夹中的 CSS 和 JS
- python - pip 安装 ssh-import-id 时没有名为“请求”的模块
- api - Twitter webhooks:沙盒包可以用于生产吗?