Azure-devops-docs: Clarify use of variables in template expressions

Created on 29 Nov 2019  Â·  3Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

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.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 devops-cictech devopprod doc-bug

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-o00o-o picture o-o00o-o  Â·  3Comments

MJECloud picture MJECloud  Â·  3Comments

dannyvv picture dannyvv  Â·  3Comments

csutorasr picture csutorasr  Â·  3Comments

cijujoseph picture cijujoseph  Â·  3Comments