Skip to content
Latchkey

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 build

Include 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.repositories and reference it with @alias.
  • A template can only be a steps, jobs, stages, or variables template - it cannot mix levels.

Related guides

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