Skip to content
Latchkey

How to Extend a Base Template With Parameters in Azure Pipelines

The extends keyword makes a pipeline inherit a base template, passing typed parameters the template uses to build out stages and jobs.

Define a template that declares parameters and lays out stages. In the consuming pipeline, use extends.template and pass values under parameters. The base controls the overall shape.

Steps

  • Write a template that declares parameters and emits stages.
  • In the pipeline, set extends.template to that file.
  • Pass values under extends.parameters.

Pipeline

azure-pipelines.yml
# azure-pipelines.yml
extends:
  template: templates/build.yml
  parameters:
    buildConfiguration: Release
    runTests: true

# templates/build.yml
parameters:
  - name: buildConfiguration
    type: string
  - name: runTests
    type: boolean
stages:
  - stage: build
    jobs:
      - job: compile
        steps:
          - script: dotnet build -c ${{ parameters.buildConfiguration }}
          - ${{ if eq(parameters.runTests, true) }}:
            - script: dotnet test

Gotchas

  • A pipeline that uses extends cannot also define top-level stages itself.
  • Template parameters are typed and evaluated at compile time, so use ${{ }} to read them.
  • Required template extends can be enforced as an environment or repo check for governance.

Related guides

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