Azure Pipelines YAML Templates

Ivan (이반) Porta
The Startup
5 min readFeb 12, 2021

--

This article will talk about YAML templates. By using these templates, you can make your code reusable and simplify sharing code across multiple pipelines.

If you are new to CI/CD, you might be familiar with blocks of code repeated multiple times in a single pipeline or deploying applications in various environments. The problem with code duplication is that block refactors must be propagated to each duplicate. Because of this, both the chance of human error and the time required to develop the pipeline increase linearly as the number of duplicates.

Using YAML templates, you can define reusable content, logic, and parameters in separate templates that load into your pipeline at runtime. You can divide these templates into one of these four categories:

  • Stage: define a set of stages for related jobs
  • Job: define a collection of steps run by an agent
  • Step: define a linear sequence of operations for a job
  • Variable: alternative to hard coded values or variable groups

Example

Suppose you have a repository which needs to be automated through CI/CD pipelines with the following structure:

.
├── api
│ ├── dockerfile
│ ├── node_modules
│ ├── package-lock.json
│ ├── package.json
│ └──…

--

--

Ivan (이반) Porta
The Startup

Senior DevOps Engineer | Terraform Associate | Certified Argo Project Associate