Introduction
As DevOps practices mature, CI/CD pipelines often grow in size and complexity. Multiple applications may share similar build, test, and deployment steps, leading to duplicated YAML code across repositories. Maintaining these duplicated pipelines becomes difficult, especially when updates need to be applied consistently across multiple projects.
Azure DevOps YAML Pipeline Templates solve this problem by allowing you to extract reusable pipeline logic into template files. Templates help standardize CI/CD processes, reduce duplication, improve maintainability, and promote consistency across teams.
In this article, you'll learn what Azure DevOps YAML Pipeline Templates are, how to create and use them, and the best practices for building reusable CI/CD pipelines.
What Are YAML Pipeline Templates?
A YAML pipeline template is a reusable YAML file that contains one or more pipeline components.
Templates can define reusable:
Steps
Jobs
Stages
Variables
Instead of repeating the same pipeline configuration across multiple projects, you reference the template wherever it is needed.
Why Use Pipeline Templates?
Without templates, teams often copy and paste YAML code between repositories.
This approach leads to:
Duplicate configurations
Difficult maintenance
Inconsistent pipelines
Higher risk of configuration errors
Pipeline templates provide several benefits:
Reusable CI/CD logic
Easier maintenance
Standardized pipelines
Reduced duplication
Faster project onboarding
Improved consistency
They are especially valuable for organizations managing many repositories.
Types of Pipeline Templates
Azure DevOps supports several types of templates.
Step Templates
Reusable collections of pipeline steps.
Job Templates
Reusable build or deployment jobs.
Stage Templates
Reusable stages containing multiple jobs.
Variable Templates
Reusable sets of variables shared across pipelines.
Choosing the appropriate template type depends on the level of reuse required.
Project Structure
A typical repository might be organized as follows:
Project
│
├── azure-pipelines.yml
├── templates
│ ├── build.yml
│ ├── test.yml
│ ├── deploy.yml
│ └── variables.yml
└── src
Keeping templates in a dedicated folder improves organization and discoverability.
Create a Step Template
Create a reusable build template.
steps:
- task: DotNetCoreCLI@2
inputs:
command: restore
- task: DotNetCoreCLI@2
inputs:
command: build
arguments: --configuration Release
This template performs package restoration and builds the application.
Use the Step Template
Reference the template in your main pipeline.
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- template: templates/build.yml
Azure DevOps expands the template during pipeline execution.
Create a Job Template
Job templates encapsulate an entire job.
jobs:
- job: Build
pool:
vmImage: ubuntu-latest
steps:
- script: dotnet build
This template can be reused by multiple pipelines.
Use the Job Template
Reference the job template.
jobs:
- template: templates/build.yml
The job becomes part of the pipeline during execution.
Create a Stage Template
Larger organizations often standardize deployment stages.
Example:
stages:
- stage: Deploy
jobs:
- job: DeployApp
steps:
- script: echo Deploying application...
Stage templates are useful for implementing consistent deployment processes across environments.
Pass Parameters to Templates
Templates become more flexible when they accept parameters.
parameters:
- name: buildConfiguration
type: string
default: Release
steps:
- script: dotnet build --configuration ${{ parameters.buildConfiguration }}
This template supports different build configurations without modification.

Join the conversation! Your thoughts help the community grow.