'Azure DevOps Pipeline - condition expression with pipeline variable
I need to make my stages in DevOps YAML pipeline dependent or not based on pipeline variable (not variable defined in the YAML).
I tried something like this:
- stage: 'test'
${{ if eq(variables.dependent_stages, 'true') }}:
dependsOn: [dev]
${{ elseif eq(variables.dependent_stages, 'false') }}:
dependsOn: []
jobs:
- deployment: approve
environment: TEST
However it always takes it as "true" as it is default value of the variable.
How to make it reflect actual value of the pipeline variable?
Solution 1:[1]
Not the solution I hoped for, but solved with parameters:
parameters:
- name: dependent_stages
displayName: Should environments depend on each other?
type: string
default: No
values:
- No
- Yes
...
- stage: 'test'
${{ if eq(parameters.dependent_stages, 'Yes') }}:
dependsOn: [dev]
${{ elseif eq(parameters.dependent_stages, 'No') }}:
dependsOn: []
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |