Skip to content
Latchkey

How to Set Pipeline-Level Variables in Azure Pipelines

A top-level variables block sets values every job and step in the pipeline can read.

Declare a variables block at the root of the pipeline. Reference values with $(Name) in scripts and inputs; they are available across all jobs and stages.

Declare and read pipeline variables

Set variables once at the top and reference them with the macro syntax.

azure-pipelines.yml
variables:
  buildConfiguration: 'Release'
  artifactName: 'webapp'

steps:
  - script: dotnet build --configuration $(buildConfiguration)
    displayName: 'Build'
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(System.DefaultWorkingDirectory)/bin'
      artifact: '$(artifactName)'

Notes

  • Use $(Var) for macro expansion at runtime; reserve ${{ }} for compile-time template expressions.
  • For secrets, mark a variable secret in a variable group rather than putting it inline.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →