Search code examples
azure-devopsyamlcontinuous-integrationazure-pipelinesazure-pipelines-yaml

Azure Pipelines Stage Condition with Variable


I am running into an issue where I'm trying to execute the following logic on the stage condition

In plain text, it should work like this:

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

The way I'm trying to do that in my YAML is like this:

  # 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 in this case is a variable that I pass into the pipeline.

Variable

I am on a release/* branch when I trigger, so I'm not sure what I'm doing wrong.


Solution

  • Here '[variables.Env]' is the issue. Please repleace it to variables['Env'].

    So your condition should be:

    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')))