This query is regarding Azure DevOps YAML pipeline. Is it possible to put an execution condition on any template defined inside ‘steps’?
For ex:
- Based on any pipeline variable value (dynamic, passed during pipeline run), decide whether to execute or not ‘Task-1.yml’
- Based on any variable value defined inside a shell script (using ##vso[task.setvariable variable=name]$value), decide whether to execute or not ‘Task-3.yml’
Below is the Azure devops yaml pipeline structure:
stages:
- stage: Stage-A
jobs:
- job: Job-A
steps:
- template : Task-1.yml
- template : Task-2.yml
- template : Task-3.yml
I was able to do this at job level, however I cannot change pipeline structure to have more than 1 jobs since I need all tasks to execute on same build agent allocated at pipeline run.
I did lot of hit and trial to achieve this but somehow this is not working for me.
Please help!
2
Answers
You cannot apply a run-time condition for pipelines. The only way is to use template expression
${{ }}
but this is evaluated at a compile-time.You can find these details here
The way I do it is passing the condition to the template like so:
And use it in the template like so: