Introduction
In this blog we will learn the Azure DevOps YAML templates.
Prerequisite
To better understand ADO template we must have basic understanding of YAML pipeline.
Stages
Jobs
Steps
If you are new to YAML you can follow below guide for easy learn --> https://www.letsdevops.net/post/letsdevops-complete-guide-to-learn-and-setup-yaml-pipeline-in-azure-devops
What is template in ADO YAML
Template in general helps to cerate some sharable content can be used by many team or in Many project.
With the help of Template we can define sharable content, logic and parameters in YAML pipeline.
Why ADO YAML template
Speed up development
secure pipeline
cleaner yaml pipeline
avoid same logic to add in multiple place
Types of templates
Include --> insert reusable control
Extends --> Insert what is allowed. define logic that other template file follow.
Templates category
stage template
job template
step template
variable template
step template syntax
Now lets understand how we can create step template and how it can be referred from another yaml pipeline file.
step template helps to group all the steps that can be sharable in many jobs or stages.
job template syntax
job template helps to group all the Jobs that can be sharable in many jobs and stages.
stage template syntax
stage template helps to group all the stages that can be sharable reference in many master pipeline.
variable template syntax
variable template helps to group all the variables that can be referenced in pipeline.
Create template with parameters
In some scenario you are required to pass some parameters to the template. We can create parameters with all types of template like step, stage, jobs, variables.
In this case we need to declare and define the parameters in two files.
In template file
the file from which template file is being called.
example:
Job Template with parameters example
Steps Template with parameters example
Variables Template with parameters example
Real Scenario example
Lets assume you want to setup of CI/CD pipeline for an Application and to better manager the pipeline you want to make use of template.
Items:
master pipeline
stage template
jobs template
steps template
GitHub Repo
Demo