Azure管道 - 阶段条件 dependson

3

我有三个环境:开发(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'

然而,上述条件不起作用,请问有谁知道执行此条件的最佳方法?

谢谢。

1个回答

2

从你的YAML示例来看,似乎存在格式问题。当使用if表达式时,不需要在YAML中添加condition字段。

您可以尝试以下示例并检查它是否可行。

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

很高兴知道它对你有用。如果这个答案可以解决问题,你可以考虑接受它作为答案。谢谢。 - Kevin Lu-MSFT

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接