When setting up an application pipeline, it’s easy to copy-paste previous CI/CD snippets. While this speeds up the initial setup, it makes maintenance and scaling a headache. By modularizing your GitLab CI/CD pipelines, you can:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Eliminate duplicated code
- Standardize workflows
- Simplify updates as your project grows

| Feature | Purpose | Scope | Cross-File Support | Syntax |
|---|---|---|---|---|
| Extends | Inherit and override job definitions | Multi-file | Yes | extends: .base_job |
| YAML Anchors | Reuse blocks within a single file | Single file | No | &anchor / <<: *anchor |
| Reference Tags | Pull snippets across YAML files | Multi-file | Yes | !reference [job, key] |

Hidden Jobs
Jobs prefixed with a dot (.) are hidden: they never run on their own but serve as reusable templates.
- Common cache rules
- Shared
before_scriptsteps - Disabling jobs without deleting them
1. The extends Keyword
Use extends to inherit from hidden or other jobs—even across multiple files. GitLab merges parent and child definitions, with child values overriding duplicates.
Example: Node.js Jobs
Any update to
.base_nodejs_job automatically applies to all jobs that extend it, keeping your pipeline DRY and consistent.2. YAML Anchors
YAML anchors (&) and aliases (*) let you reuse blocks within the same file.
YAML anchors do not work across multiple files. Use
extends or !reference for cross-file reuse.3. Reference Tags
GitLab’s custom!reference tag imports specific sections from other jobs even across files.
!reference tags require GitLab Runner 12.6+ and allow fine-grained imports of job snippets.Further Reading
- GitLab CI/CD Pipeline Configuration Reference
- YAML Anchors and Aliases
- Using
extendsin GitLab CI/CD - Reference Tags (
!reference)
extends, YAML anchors, and !reference tags, you can keep your GitLab CI/CD pipelines maintainable, scalable, and free from repetition.