Back to writing

Developer Experience

What Makes CI/CD Templates Actually Useful

What I learned moving our Azure DevOps pipelines to YAML and into one shared, versioned template repository.

· 4 min read

  • CI/CD
  • DevEx
  • Azure DevOps

Most of our Azure DevOps pipelines had started as copies of other pipelines. Many still lived in the classic UI editor, where a change can't be reviewed and has no history next to the code. Teams kept rebuilding the same build, test, packaging and deploy steps, and the copies drifted apart.

I moved the pipelines to YAML, then pulled the repeated steps into one shared template repository.

What went into templates

I started from what the pipelines were already doing instead of designing a library. Building, running tests, packaging and deploying showed up in nearly all of them, each with small differences nobody had chosen on purpose. A step only one project needed stayed in that project's pipeline.

Parameters

Once other pipelines depend on a template, its parameters are a public interface, and renaming one breaks someone's build. I kept the list short, gave each parameter a default that works for the common case, and named them for what they mean to the person using the template. A team should be able to read its own pipeline without opening the template repository. Using one looks like this:

resources:
  repositories:
    - repository: templates
      type: git
      name: Shared/pipeline-templates
      ref: refs/tags/v2.3.0

steps:
  - template: dotnet/build-and-test.yml@templates
    parameters:
      solution: src/App.sln

A template with twenty parameters doesn't save anyone much. One that hides every step behind a vague name is hard to debug when it fails.

Versioning

Pipelines don't point at the template repository's main branch. They point at a semantic version tag:

  • A patch release fixes something without changing behavior.
  • A minor release adds something optional.
  • A major release changes the contract.

Each team decides when to move up. I can keep improving the templates without breaking another team's release build, and a breaking change goes into a new major version while the old tag keeps working for anyone who isn't ready.

Where projects differ

Projects differ in paths, test projects and deploy targets, so the templates need room for that. If every step can be overridden, though, the template keeps nothing consistent. I allowed the variations that were real, like paths, optional stages and environment values, and kept the order of the steps and the safety checks the same for everyone.

Failures

Step names say exactly what they do, so the failing one is obvious in the log. Failures happen close to their cause, and artifact names and variables are predictable enough that you can work out what happened without reading the template's source.

Docs

Short docs live next to the templates: a minimal example, a fuller one, what each parameter does, and what changed in each major version.

Pipelines are now defined the same way across teams, complex ones take less time to set up, and a fix to a shared step is made once. They're code we review and version instead of settings in a UI.