I have got an Azure Pipeline already running. Now I want to execute a sequence of steps only if a certain condition becomes true during runtime.
Example
steps:
- template: steps_checkout.yml
# some more steps here
- bash: |
if [ some condition ]; then
echo "##vso[task.setVariable variable=rebuild_lib]false"
echo "Did set rebuild_lib to false"
fi
- if eq( variables.rebuild_lib, true) ):
- template: steps_lib_build.yml
The line if eq( variables.rebuild_lib, true) )
does not work, because it is not a correct condition syntax. I could use
${{ if eq( parameters.something, true ) }}
but that needs to be known at runtime.
Accodring to https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
an expression can also be $[ if eq(variables.rebuild_lib), true]
to be evaluated at runtime, but using this, I get
Unexpected value '$[ if eq( variables.rebuild_lib, true) ) ]'
Seems like the yml cannot be modified at runtime this way.
So how do I decide to use a template at runtime?
I could imagine giving the variable as parameter to the next template adapter.yml. This template adapter.yml gets then the variable as parameter and could use the ${{}} expression and again use the next template steps_lib_build.yml ... but creating templates only for that seems somehow ... workaroundish.
Also using something like
- template: steps_lib_build.yml
condition: ...
does not work.
Is there a good way to do this?