I've found a lot of instances in a pipeline I have to work with where either intentionally or not, steps in the same job as one defining a non-output task variable use said variable as an environment variable in a shell script (regular $
-sign syntax within Bash script), rather than within one of the Azure DevOps expression contexts such as macro-style $(name)
reference or run-time expression $[name]
. The set of environments involved seem to be those of all shell-based steps within the job, including the defining step (contrary to the task variable).
Presence in the environment can be confirmed by running env
in any step that executes a Bash script.
Is this supported behavior that can be relied upon? I haven't found any mention of this behavior when reading up on expressions and different kinds of variables, then again, Azure DevOps docs seem to be messy and full of holes.
I've experimented a bit and it turns out, this only applies to non-output task variables, though output variables are also exported under a slightly altered name startnig with a prefix that denotes the step, though only to the defining step's environment, not to subsequent steps' environments either within the same job or elsewhere.
This is the supported and intended behavior, as far as I am aware.
You can see mention of this in the documentation here:
System and user-defined variables (except secret variables) also get injected as environment variables for your platform. When variables convert into environment variables, variable names become uppercase, and periods turn into underscores. For example, the variable name any.variable becomes the variable name $ANY_VARIABLE.
Pipeline parameters, predefined variables, user defined variables and outputs are all defined as environment variables on the OS of the agent.
I often include this .yaml
snippet as the first step in each of my jobs. This will output the key/value of all OS environment variables at the start of an agent run.
- task: PowerShell@2
displayName: Print all variables
inputs:
targetType: "inline"
script: |
dir env: