Course contentsShow
← Cloud and Infrastructure
Lesson 1757 of 2,98936. GitLab CI/CDFree lesson

Pipeline Templates and Includes

Learn to reuse pipeline configuration with include keyword, templates, and external files for DRY principles.

Pipeline Templates and Includes

What you'll learn: How to eliminate repetition in your GitLab CI configuration by reusing pipeline templates and external files.

The Core Problem: Repeating Yourself

Imagine copying the same CI job definitions into ten different repositories. When you need to update that job, you'd have to edit all ten files—a maintenance nightmare. GitLab's include keyword and pipeline templates solve this by letting you reference shared configuration instead of duplicating it.

How Pipeline Includes Work

The include keyword pulls external YAML configuration into your .gitlab-ci.yml file. Think of it like importing a library in code—you write once, reuse everywhere.

include:
  - local: 'templates/security-scan.yml'
  - project: 'company/ci-templates'
    file: '/templates/deploy.yml'
  - remote: 'https://example.com/ci/common.yml'
  - template: 'Security/SAST.gitlab-ci.yml'

Four Include Types

  • local: Include files from the same repository
  • project: Reference files from other GitLab projects
  • remote: Pull configuration from any URL
  • template: Use GitLab's official templates (e.g., security scanning, code quality)

DRY Principles in Action

Instead of copying 50 lines of Docker build logic across projects, store it once in company/ci-templates/docker-build.yml. Every project simply includes it. Update the template once, and all pipelines get the improvement automatically.

Combine include with extends to customize shared templates per project while keeping core logic centralized.

Key Takeaway: Pipeline templates and the include keyword let you centralize CI/CD configuration, making updates easier, reducing errors, and following the DRY (Don't Repeat Yourself) principle across all your projects.