带有变量的 Azure Pipelines 阶段条件

时间:2021-06-30 15:11:42

标签: azure-devops continuous-integration yaml azure-pipelines

我遇到了一个问题,我试图在 stage condition

上执行以下逻辑

在纯文本中,它应该像这样工作:

(branch is release AND var undefined) OR (branch is release AND var == sys)

我在 YAML 中尝试这样做的方式是这样的:

  # SYS
  - stage: BuildSYS
    condition: or(and(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), eq('[variables.Env]', '')), and(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), eq('[variables.Env]', 'SYS')))
    jobs:
      - job: 
        steps:
          - script: echo Hi form SYS!

Env 在这种情况下是我传递到管道中的变量。

Variable

触发时我在 release/* 分支上,所以我不确定我做错了什么。

1 个答案:

答案 0 :(得分:1)

这里 '[variables.Env]' 是问题所在。请将其替换为 variables['Env']

所以你的条件应该是:

condition: or(and(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), eq(variables['Env'], '')), and(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), eq(variables['Env'], 'SYS')))