Your GitLab CI pipelines have become unmaintainable with copy-pasted YAML across 30+ projects. How do you implement reusable CI/CD components using includes, extends, YAML anchors, and GitLab CI/CD components? What is the migration strategy?
Quick Answer
Create a central CI/CD templates repository with reusable job definitions, use include:project for cross-project includes, extends for job inheritance, and migrate to GitLab CI/CD Components (catalog) for versioned, discoverable pipeline building blocks with defined inputs.
Detailed Answer
The DRY Problem in GitLab CI
When organizations grow, teams copy-paste CI/CD configurations, leading to drift, inconsistent security practices, and maintenance nightmares. A fix to the Docker build process needs updating in 30 files. The solution is a layered approach: YAML anchors for intra-file reuse, extends for job inheritance, include for cross-file composition, and CI/CD Components for versioned, cataloged building blocks.
Include Strategies
include:project pulls YAML from another repository—ideal for a central templates repo. include:remote pulls from any URL (useful for open-source templates). include:template uses GitLab's built-in templates. include:local references files within the same project. Templates can be overridden by the including project—jobs defined in includes are merged with local definitions, with local values taking precedence.
CI/CD Components (GitLab 17+)
Components are the evolution of includes—they provide versioned, documented, discoverable pipeline building blocks with declared inputs and outputs. Published to the CI/CD Catalog (like a marketplace), they have semantic versioning, input validation, and usage documentation. Components solve the versioning problem that raw includes have: you can pin to @1.2.3 and upgrade deliberately rather than being broken by upstream changes.
Migration Strategy
Phase 1: Identify common patterns across projects (Docker build, deploy to K8s, security scanning). Phase 2: Extract into a templates repository using include:project with ref pinning. Phase 3: Add versioning via Git tags on the templates repo. Phase 4: Migrate to CI/CD Components for better discoverability and input validation. Each phase is backward-compatible—projects can migrate incrementally.
Governance and Standards
The platform team owns the templates repository with branch protection and code review requirements. Changes go through a testing pipeline that validates templates against sample projects. Use compliance pipelines (Ultimate) to enforce that certain includes cannot be overridden—ensuring security scanning always runs regardless of project-level configuration.