Notes on GitLab CI/CD templating
2026-10-20 • 4 mins

# CI/CD templates

# Templates repository structure

I recommend the following structure for a shared templates repository

.
├─ templates
├─ jobs
│   └─ MAIN.gitlab-ci.yml
└─ helpers

# A shared MAIN.gitlab-ci.yml

In the above structure, I also defined a jobs/MAIN.gitlab-ci.yml. This file contains the following:

stages:
- lint
- test
- build
- scan
- approval
- deploy

include:
- templates/lint.yml
- templates/test.yml
- templates/build.yml
- templates/scan.yml
- templates/approval.yml
- templates/deploy.yml

When working in a multi-repo project, I often have multiple repositories consuming the same templates repository with the same stages and include keys. This file helps to consolidate such common configuration into one place so that we only have to define this in all project repositories .gitlab-ci.yml:

include:
  - project: "my-group/cicd-templates"
    ref: main
    file: jobs/MAIN.gitlab-ci.yml

This file is also useful to define any shared jobs that will be the same in all repositories (eg. secret_detection and semgrep-sast scans)

# Needs and dependencies

# Know when to use parallel:matrix

# Manual jobs

When using when: manual to define manual jobs, the location of the key determines the type of manual job created:

# Speeding up jobs

# Artifacts and reports

# Terraform

WIP

# References

Last Updated: 2026-10-20