Skip to content
Latchkey

How to Use Variable Templates in Azure Pipelines

A variable template is a YAML file of variables that pipelines pull in under their variables key.

Define common variables once in a template, then include it from each pipeline so they all share the same values and updates land in one place.

Include a shared variable file

The main pipeline pulls variables from a template file alongside its own.

azure-pipelines.yml
variables:
  - template: vars/common.yml
  - name: serviceName
    value: web

steps:
  - script: echo "Deploying $(serviceName) to $(environmentName)"

The template file

common.yml just declares reusable variables.

vars/common.yml
variables:
  - name: environmentName
    value: production
  - name: region
    value: eastus

Related guides

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