Azure 管道 - 阶段条件依赖

Azure pipeline - Stage condition dependson

我有三个环境:dev、hml 和 qa。

在我的管道中,根据分支阶段有一个条件来检查它是否 运行:

- stage: Project_Deploy_DEV
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/dev')
  dependsOn: Project_Build

- stage: Project_Deploy_HML
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/hml')
  dependsOn: Project_Build

我在做qa阶段,我想放一个条件,根据分支,dependson参数会改变:

- stage: Project_QA
   condition:
     ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
       dependsOn: 'Project_Deploy_DEV'
     ${{ if eq(variables['Build.SourceBranchName'], 'hml') }}:
       dependsOn: 'Project_Deploy_HML'

但是,上述条件不起作用,有人知道执行此条件的最佳方法吗?

谢谢

从您的 YAML 示例来看,似乎存在格式问题。使用if表达式时,无需在YAML中添加条件字段

您可以尝试下面的示例,看看是否可行。

stages:
  - stage: A
    jobs:
      - job: test
        steps:
          - xxx

  - stage: B
    jobs:
      - job: test
        steps:
          - xxx
  - stage: C
    ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
      dependsOn: A
    ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
      dependsOn: B  
    jobs:
      - job: test
        steps:
          - xxx