When every team writes their own pipeline, a year later you have twenty ways to build the same thing and no way to update them all at once. A vulnerability in a linter, a new kubeconform version, a runner image change — all of it gets patched by hand in twenty places. The cure is a shared template catalog.
Connecting — one line
include:
- project: infra/ci-templates
ref: v2
file: /ansible-lint.yml
That's it: the project gets a ready job with the current linter version, runner registration and caching. Changes to the template arrive with a new tag version — deliberately.
How the template itself is built
A template is an extendable job with a predictable contract: input — variables, output — an artifact or a verdict:
# infra/ci-templates: ansible-lint.yml
.ansible-lint:
stage: test
image: ghcr.io/ansible-community/molecule:latest
before_script:
- ansible --version
script:
- ansible-lint --offline
variables:
ANSIBLE_CONFIG: $CI_PROJECT_DIR/ansible.cfg
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
The project uses it without thinking about the internals:
include:
- project: infra/ci-templates
ref: v2
file: /ansible-lint.yml
ansible-lint:
extends: .ansible-lint
The rules that keep the catalog alive
- Versions as tags. Teams upgrade deliberately:
ref: v2→ref: v3is a visible MR in the project, not "someone changed master and our stuff broke". - A template is a contract. Change the inside, keep the outside interface: renaming a required variable is a major version with a changelog and a migration note.
- All standard checks live in the catalog: ansible-lint, yamllint, kubeconform for manifests, security scans (trivy), image build and publishing. A project doesn't write "its own" scan — it includes a ready one.
- The catalog has its own CI. Every template is verified against a test project on MR: a broken template gets caught before twenty teams include it.
The catalog in numbers
| Without a catalog (20 projects) | With a catalog |
|---|---|
| update the linter in 20 places | 1 MR in the catalog + 20 deliberate tag bumps |
| 20 different tool versions | 1 version for the organization |
| "just to check" copy-paste without review | review of changes in one place |
| new project: a day per pipeline | new project: 15 minutes per include |
Common implementation mistakes
- An ownerless catalog. "Shared" without a responsible person degrades into a template dump; an owner and review rules are mandatory from day one.
- Stub templates without a contract. If a template needs 15 variables "to figure out", nobody will use it. A good template works with defaults and is optionally configurable.
- ref: master instead of tags. "Always fresh" = "always broken for someone": tags are about respect for other people's time.
- One template for every occasion. If the template grows ifs "for project A" and "for project B" — time to split it in two. A template solves one task, like a role in Ansible.
How to start from zero
- Collect the teams' most "mature" pipelines and extract the common part: usually 90% of steps match.
- Start with two or three templates: a linter, an image build, a deploy. Don't try to cover everything at once.
- Move one pilot project, break in the contract, gather feedback.
- Migrate the rest team by team, not all at once: each with a deliberate tag bump.
The savings are modest at the start and huge over the distance: one change in a template — and the whole organization's pipelines are updated. The key is keeping the contract honest and the versions visible.
A CI template catalog is the organization's library. A library stays in order not through prohibitions but because going there is easier than writing your own.
Templates for "build an image" and "deploy": the catalog's heart
# infra/ci-templates/build-image.yml
.build-image:
stage: build
image: docker:27
services: [docker:27-dind]
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
- IMAGE="$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
- docker build --cache-from "$CI_REGISTRY_IMAGE:cache" -t "$IMAGE" -t "$CI_REGISTRY_IMAGE:cache" .
- docker push "$IMAGE" --all-tags
after_script:
- docker logout "$CI_REGISTRY"
The contract: CI_* variables come from GitLab; the project only needs a Dockerfile. The internals (dind, cache-from, tagging) are the template's business — the team never thinks about them.
Versioning without magic
| Change | Version type | What teams do |
|---|---|---|
| linter updated in the image | patch (v2.1.3) | nothing — the include didn't change |
| a new input parameter with a default | minor (v2.2.0) | nothing until the parameter is needed |
| a variable renamed | major (v3.0.0) | a deliberate MR with a changelog note |
This approach works under one condition: the catalog has a CHANGELOG.md, and an MR without an entry in it doesn't get merged. The one-line rule of review.
Catalog health metrics
- Share of projects on the current major — the main KPI; those lagging are not "guilty" but a reason to simplify the migration.
- Time to connect a new project — from "include" to a green pipeline. More than an hour means the templates demand too many required variables.
- The number of template forks — the main anti-KPI: a fork means the catalog doesn't answer the need. Every fork is a "why" review and a template fix.