Skip to main content

Command Palette

Search for a command to run...

Using Simple Pipeline Templates in Azure DevOps

Implementing DRY practices

Published
2 min read
Using Simple Pipeline Templates in Azure DevOps
J

Executive technology leader responsible for platform reliability, cloud operations, security posture, and enterprise technology risk within an investor-backed fintech environment. I lead technology operations at the intersection of engineering execution, governance, and business outcomes — ensuring platforms are scalable, resilient, and trusted by investors, regulators, and clients.

Currently VP of DevOps at InvestorFlow, where I focus on building board-ready technology operations, strengthening risk and resilience, and shaping long-term platform strategy to support growth and regulatory confidence.

How to create a simple Pipeline Template

Create a file in a new or existing pipelines folder in your repository. I like to store these files in a directory of devops/pipelines/templates. Name the file based on the template action you would like to take. For my example, I will create a simple template for running a docker container called Super Linter, so I will call my file super-linter.yaml.

My template will have one step and will look like this:

steps:
    - script: |
        docker pull github/super-linter:latest
        docker run -e RUN_Local=true -e VALIDATE_GITLEAKS=true -v $(System.DefaultWorkingDirectory):/tmp/lint github/super-linter
      displayName: "Run Super Linter"

Save the file when ready.

How to use a template within the same Repository

In your existing pipeline file or a new one (not the template file), you can select the template file so it can be reused. To do this, you will need to add a self checkout step first:

steps:
- checkout: self

Then you will need to add the template file path as a next step to run the template:

- template: devops/pipeline/templates/super-linter.yaml

Remember, the template file path will differ from mine depending on where you locate your pipeline file.

How to use a template stored in a different Repository

Suppose you want to make this a reusable file across your entire repository stack, giving you a central location for templates across all projects. In that case, you will need to store this file in a repository and then complete the following in the pipeline file of the repo you want to run the pipeline from:

resources:
    repositories:
    - repository: name
      type: type
      endpoint: endpoint
      name: repo name
      ref: branch name

steps:
- checkout: self
- template: path/to/template/repo

The repositories section is the connection details to the repo where the template is stored. Follow these instructions to connect to your service connection/provider

Please make sure you change the template path to the path of the template repo.

More from this blog

J

James Cook - Cloud and DevOps

73 posts

James is a Microsoft MVP with more than a decade of career experience in the tech space. James's blog focuses on all areas of Cloud and DevOps.