While it could be extrapolated from the statement that the expression variables are evaluated before the job runs, it should be clarified that variables cannot be used in template expressions, with the exception being predefined variables. Also worth mentioning that variables cannot be passed as parameters.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
This limitation on the use of variables with templates in pipelines is really limiting and frustrating. Is there any intention to change this behaviour to something sensible?
We can also just document the existing behavior (eval at compile or runtime) better, for example:
jobs:
- job: build
variables:
- foo: bar
steps:
- bash: |
echo $(foo) # This will be bar
echo '##vso[task.setvariable variable=foo]baz'
echo $(foo) # This will also be bar, $(foo) expands before the step
- bash: echo $(a) # This will be baz. The variable is expanded just before the step
Source: https://adamtheautomator.com/azure-devops-variables-complete-guide/
After understanding this difference, everything worked for me.
Thanks @julie-ng and @MarkKoz. Updating the docs now.