Rediģēt

Kopīgot, izmantojot


variables definition

Define variables using name/value pairs.

Definitions that reference this definition: pipeline, stages.stage, jobs.job, jobs.deployment

Definitions that reference this definition: pipeline, jobs.job

Implementations

Implementation Description
variables: string dictionary Define variables using name/value pairs.
variables: variable list Define variables by name, variable group, or in a template.

Remarks

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.

variables: string dictionary

Define variables using name/value pairs.

variables:
  string: string # Name/value pairs

None.

Examples

For a simple set of hard-coded variables, use this mapping syntax:

variables: { string: string }

Variables defined at different scopes:

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)
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)

variables: variable list

Define variables by name, variable group, or in a template.

variables: [ name | group | template ] # Define variables by name, variable group, or in a template.

List types

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.

Examples

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

You can also include variables from templates.

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

See also