【发布时间】:2021-01-23 00:00:24
【问题描述】:
我正在尝试创建一个包含三个阶段的 yaml 管道,这些阶段可以根据拉取请求源分支以不同的顺序执行。例如:
如果 var = 默认则
- A阶段
- B阶段
- C阶段
如果 var != 默认则
- A阶段
- C阶段
- B阶段
这是我目前所拥有的: 变量:
- name: abcDependsOn
${{ if not(contains(variables['System.PullRequest.SourceBranch'], 'hotfix' )) }}:
value: 'Publish'
${{ if contains(variables['System.PullRequest.SourceBranch'], 'hotfix' ) }}:
value: 'DeployXYZ'
- name: xyzDependsOn
${{ if not(contains(variables['System.PullRequest.SourceBranch'], 'hotfix' )) }}:
value: 'DeployABC'
${{ if contains(variables['System.PullRequest.SourceBranch'], 'hotfix' ) }}:
value: 'Publish'
stages:
- stage: Publish
jobs:
- job: publish
- stage: DeployABC
dependsOn: ${{ variables.abcDependsOn }}
jobs:
- job: deployabc
- stage: DeployXYZ
dependsOn: ${{ variables.xyzDependsOn }}
jobs:
- job: deployxyz
这是行不通的,因为在运行时表达式变量之前评估了 dependsOn 模板表达式变量(我认为)。这甚至可能吗?
【问题讨论】:
标签: azure-devops yaml azure-pipelines azure-pipelines-yaml