title | description | ms.date | monikerRange |
---|---|---|---|
variables definition |
Define variables using name/value pairs. |
05/14/2024 |
>=azure-pipelines-2019 |
:::moniker range=">=azure-pipelines-2019"
Define variables using name/value pairs.
:::moniker-end
:::moniker range=">=azure-pipelines-2020"
Definitions that reference this definition: pipeline, stages.stage, jobs.job, jobs.deployment
:::moniker-end
:::moniker range=">=azure-pipelines-2019 <=azure-pipelines-2019.1"
Definitions that reference this definition: pipeline, jobs.job
:::moniker-end
:::moniker range=">=azure-pipelines-2019"
Implementation | Description |
---|---|
variables: string dictionary | Define variables using name/value pairs. |
variables: variable list | Define variables by name, variable group, or in a template. |
:::moniker-end
The variables
keyword uses two syntax forms: variable list and mapping (string dictionary).
In mapping syntax, all keys are variable names and their values are variable values. To use variable templates, you must use list syntax. List syntax requires you to specify whether you're mentioning a variable (name
), a variable group (group
), or a template (template
).
You can't use list and mapping variables in the same variables section, but you can combine name
, group
, and template
when using list syntax.
You can specify variables at the pipeline, stage, or job level.
:::moniker range=">=azure-pipelines-2019"
Define variables using name/value pairs.
variables:
string: string # Name/value pairs
None.
:::moniker-end
For a simple set of hard-coded variables, use this mapping syntax:
variables: { string: string }
Variables defined at different scopes:
::: moniker range=">= azure-pipelines-2020"
variables: # pipeline-level
MY_VAR: 'my value'
ANOTHER_VAR: 'another value'
stages:
- stage: Build
variables: # stage-level
STAGE_VAR: 'that happened'
jobs:
- job: FirstJob
variables: # job-level
JOB_VAR: 'a job var'
steps:
- script: echo $(MY_VAR) $(STAGE_VAR) $(JOB_VAR)
::: moniker-end
::: moniker range=">= azure-pipelines-2019 <= azure-pipelines-2019.1"
variables: # pipeline-level
MY_VAR: 'my value'
ANOTHER_VAR: 'another value'
jobs:
- job: FirstJob
variables: # job-level
JOB_VAR: 'a job var'
steps:
- script: echo $(MY_VAR) $(STAGE_VAR) $(JOB_VAR)
::: moniker-end
:::moniker range=">=azure-pipelines-2019"
Define variables by name, variable group, or in a template.
variables: [ name | group | template ] # Define variables by name, variable group, or in a template.
Type | Description |
---|---|
variables.name | Define variables using name and full syntax. |
variables.group | Reference variables from a variable group. |
variables.template | Define variables in a template. |
:::moniker-end
To include variable groups, switch to this sequence syntax:
variables:
- name: string # name of a variable
value: string # value of the variable
- group: string # name of a variable group
You can repeat name
/value
pairs and group
.
Variables can also be set as read only to enhance security.
variables:
- name: myReadOnlyVar
value: myValue
readonly: true
::: moniker range=">=azure-pipelines-2020"
You can also include variables from templates.
::: moniker-end
Sequence syntax:
variables:
- name: MY_VARIABLE # hard-coded value
value: some value
- group: my-variable-group-1 # variable group
- group: my-variable-group-2 # another variable group