Pipeline Templates: Reusable CI/CD Building Blocks
Think of pipeline templates as versioned, shareable functions for your CI/CD. Instead of copy-pasting YAML, you import a standardized block of logic for tasks like security scanning or deployment.
Why it exists
As organizations scale, CI/CD configurations become repetitive and hard to manage. Copy-pasting YAML across hundreds of repositories leads to inconsistencies, makes updates difficult, and prevents standardization of best practices like security scanning. Pipeline templates solve this by centralizing reusable logic.
The mental model
Think of a pipeline template as a function or a library for your CI/CD system. Instead of writing the same logic to run a linter or deploy to staging in every project's pipeline file, you call a pre-built, versioned template. This template can accept parameters (inputs) to customize its behavior, just like a function takes arguments.
How it works
A template is typically a YAML file defining a set of CI/CD jobs or steps. These templates are stored in a dedicated repository, often called a "component project." This project acts as a container for one or more related templates, which are versioned together using Git tags. Other projects can then import a specific version of a template. For example, a project's main pipeline file might include a reference like component: my-org/templates/security-scan@v1.2.0. The CI/CD runner fetches the template from that version and merges it into the project's pipeline.
When to use it
Use templates for any CI/CD logic that is repeated across multiple projects. This is perfect for enforcing standards, such as requiring all services to run a specific security scanner, use a standard build process, or deploy using a consistent set of steps. They are also great for creating a catalog of optional, pre-approved pipeline tasks that developers can easily discover and use.
When not to use it
Avoid creating templates for logic that is truly unique to a single project. Over-abstracting highly specific deployment steps can make the template complex and brittle. If a "reusable" template ends up with dozens of inputs and conditional logic to handle edge cases for different projects, a simpler, project-specific configuration is better.
One canonical example
A platform team creates a repository to host a secret-detection template. The template is defined in templates/secret-detection.yml and contains the YAML for a job that runs a scanner. The team tests it and releases version v1.0.0. Now, any other team can add it to their CI/CD configuration by including the component and referencing v1.0.0. When the platform team improves the scanner and releases v1.1.0, other projects are unaffected until they explicitly update their configuration to use the new version, preventing unexpected breakages.
Interview question
When is it generally LEAST advisable to use a pipeline template?
- a.When the logic is highly specific and unique to a single projectCorrect
- b.When standardizing a common build process across many applications
- c.When the template requires input parameters to adapt its execution
- d.When the logic needs to be versioned and shared across teams
Why? this is the answer
The card explicitly states to avoid templates for "logic that is truly unique to a single project" to prevent over-abstraction and complexity. The other options describe scenarios where templates are beneficial or how they function, making them suitable for template implementation.
Just read this? Test yourself on what you have been reading.
Read the original → docs.gitlab.com
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on ci/cd — each one lists the topics its interview covers.
See open roles