How to Reuse Pipeline Templates in Azure Pipelines
Templates factor shared steps or jobs into a reusable file that other pipelines include with typed parameters.
Define a template with parameters: and steps:, then include it with - template: and pass values. This keeps common build logic in one place.
A parameterized steps template
The template declares a typed parameter; the caller passes a value when including it.
templates/build-steps.yml
# build-steps.yml
parameters:
- name: nodeVersion
type: string
default: '20.x'
steps:
- task: NodeTool@0
inputs:
versionSpec: ${{ parameters.nodeVersion }}
- script: npm ci && npm run buildInclude it from the pipeline
Reference the template file and override the parameter as needed.
azure-pipelines.yml
steps:
- template: templates/build-steps.yml
parameters:
nodeVersion: '22.x'Gotchas
- Template expressions
${{ }}resolve at compile time, before runtime variables exist. - To share templates across repos, declare the repo under
resources.repositoriesand reference it with@alias. - A template can only be a steps, jobs, stages, or variables template - it cannot mix levels.
Related guides
How to Use Variable Groups and Secrets in Azure PipelinesShare variables and secrets across Azure Pipelines with library variable groups - link them, mark secrets, an…
How to Use a Matrix Strategy in Azure PipelinesFan a job out across versions or configurations in Azure Pipelines with strategy.matrix, named legs, maxParal…