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
parametersand emitsstages. - In the pipeline, set
extends.templateto 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 testGotchas
- A pipeline that uses
extendscannot also define top-levelstagesitself. - 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
How to Use a Variable Group in Azure PipelinesShare values across Azure Pipelines runs by linking a Library variable group with the group keyword, then ref…
How to Conditionally Run a Stage or Job in Azure PipelinesRun an Azure Pipelines stage or job only when a condition holds using the condition key with expressions like…