How do I create and use a GitLab CI/CD component?

By Melih Toksari, developer of MergeBell · Updated · 5 min read

Short answer

Put each component in a project's top-level templates/ folder, as templates/<name>.yml or templates/<name>/template.yml, with an optional spec:inputs header above a --- line. Use it with include: - component: $CI_SERVER_FQDN/<project-path>/<name>@<version>, and publish it to the CI/CD Catalog by turning on the project's CI/CD Catalog toggle and creating a release from a semantic-version tag with the release keyword in a CI job.

A GitLab CI/CD component is a YAML file in a project’s top-level templates/ directory, usually with a spec:inputs header so users can configure it. Projects pull it in with include: component, pinned to a version:

include:
  - component: $CI_SERVER_FQDN/my-org/security-components/secret-detection@1.0.0
    inputs:
      stage: build

Components work on every tier, on GitLab.com, Self-Managed and Dedicated. Compared with a plain include, they add three things: they can be listed in the CI/CD Catalog, released and used at a specific version, and several components in one project are versioned together.

How do I set up a component project?

A component project is an ordinary GitLab project that hosts one or more components, up to 100 per project. All of them share the project’s versions, so a component that needs its own release cycle belongs in its own project.

The repository needs:

  • A README.md documenting every component in the project.
  • A top-level templates/ directory holding the components.
  • Ideally a .gitlab-ci.yml that tests the components and creates releases, and a LICENSE.md.

Each component is either a single file or a folder:

├── templates/
│   ├── my-component.yml
│   └── my-other-component/
│       ├── template.yml
│       ├── Dockerfile
│       └── test.sh
├── LICENSE.md
├── README.md
└── .gitlab-ci.yml

In a folder, only template.yml is used by other projects. The Dockerfile and test.sh stay in the repository for building images or tests but aren’t released with the component. File and folder names can use letters, numbers, _, - and ., so templates/secret-detection.enterprise.yml is valid.

What goes in the component file?

A spec section, a --- line, then ordinary pipeline configuration. Inputs are read with $[[ inputs.<name> ]]:

spec:
  inputs:
    stage:
      default: test
---
unit-test:
  stage: $[[ inputs.stage ]]
  script: echo unit tests

integration-test:
  stage: $[[ inputs.stage ]]
  script: echo integration tests

spec accepts three keywords: description (shown in the catalog), inputs, and component, which exposes the component’s own name, sha, version and reference as $[[ component.version ]] and so on. spec:include isn’t allowed in components: define inputs in the component itself.

Prefer inputs to custom CI/CD variables. If a required input isn’t passed, GitLab returns a pipeline error; an undefined variable is silently empty. Keep variables for predefined values and for secrets stored as masked or protected variables in project settings.

How do I use a component in my pipeline?

Add it with include: component and the reference <fully-qualified-domain-name>/<project-path>/<component-name>@<version>:

stages: [verify, release]

include:
  - component: $CI_SERVER_FQDN/myorg/ruby/test@1.0.0
    inputs:
      stage: verify

$CI_SERVER_FQDN is the predefined variable for your GitLab host. You can only reference components on the same instance as your project. If the component project is private, you need at least the Reporter role in it to use the component.

The component’s jobs merge into your pipeline configuration. Two jobs with the same name merge into one, and an extends in the component can pick up a same-named job of yours by accident. Keep names distinct unless you mean to override the component.

Which version should I reference?

The text after @ can be any of these, highest priority first:

Reference Example Notes
Commit SHA @e3262fdd0914fa823210cdb79a8c421e2cef79d8 Wins over a tag of the same name; GitLab’s preferred pin for security
Tag @1.0.0 Catalog releases must be semantic versions; wins over a branch of the same name
Branch @main Moving target; useful for testing
Partial version @1 or @1.2 Latest matching catalog release; never a pre-release
~latest @~latest Latest catalog release, including breaking major versions

With versions 1.0.0, 1.1.0, 1.1.1, 1.2.0, 2.0.0, 2.0.1 and 2.1.0 published, @1 resolves to 1.2.0, @1.1 to 1.1.1, and @~latest to 2.1.0. Partial versions and ~latest only work for components published in the CI/CD Catalog. A pre-release such as 1.0.1-rc has to be named in full.

How do I test and release a component?

Test it from its own project’s .gitlab-ci.yml by including it at the current commit:

include:
  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA
    inputs:
      stage: build

stages: [build, test, release]

create-release:
  stage: release
  image: registry.gitlab.com/gitlab-org/cli:latest
  script: echo "Creating release $CI_COMMIT_TAG"
  rules:
    - if: $CI_COMMIT_TAG
  release:
    tag_name: $CI_COMMIT_TAG
    description: "Release $CI_COMMIT_TAG of components in $CI_PROJECT_PATH"

Add a test job that checks the component’s jobs exist and behave, and let the tag pipeline run those tests before create-release.

How do I publish it to the CI/CD Catalog?

You can use a component without publishing it. Publishing makes it findable under Search or go to > Explore > CI/CD Catalog. Work through this checklist:

  1. Owner role: in Settings > General > Visibility, project features, permissions, turn on CI/CD Catalog project.
  2. Project description set, and a root README.md at the tagged commit.
  3. At least one component in templates/ at the tagged commit.
  4. A release job using the release keyword, like the one above. Releases made through the Releases API don’t publish to the catalog.
  5. A semantic-version tag such as 1.0.0, pushed by someone with the Maintainer or Owner role. The tag pipeline runs the release job, and the new version appears in the catalog.

Catalog visibility follows the project: private components are visible only to project members, internal ones to signed-in users, public ones to anyone who can reach the instance. To unpublish, turn the toggle off; that deletes the catalog metadata but keeps the project.

Why does my component fail, and how do I fix it?

The two errors the docs call out:

This GitLab CI configuration is invalid: Component 'gitlab.com/my-namespace/my-project/my-component@~latest' - content not found

~latest or a partial version found no published release. Create a new release.

Build component error: Spec must be a valid json schema

Usually an empty spec:inputs: block. If the component has no inputs, leave spec: empty above the --- line instead.

Other habits that prevent surprises: don’t hard-code the stage or job names (take them as inputs), avoid global keywords like default, which affect every job in the including pipeline, and use $CI_SERVER_FQDN and $CI_API_V4_URL rather than gitlab.com URLs so the component also works on a mirror. If you only need to share a file between your own projects, include:project is simpler.

Is it safe to use someone else’s component?

Anyone can publish to the catalog, and GitLab can’t vouch for third-party components. Read the source before you use it, pin a commit SHA rather than ~latest, give it minimally scoped, short-lived tokens, and review the diff before moving to a new version. Badges help: GitLab-maintained, GitLab Partner and Verified creator components are marked in the catalog.

When a component’s job fails in a pipeline, it shows up like any other job. MergeBell shows a pipeline’s jobs grouped by stage with the job log tail, so you can see which component job broke and retry it from your phone.

Frequently asked questions

What is a GitLab CI/CD component?

A reusable unit of pipeline configuration, kept in a component project and pulled into a pipeline with include:component. Unlike a plain include, a component can take inputs, be released with a version, and be listed in the CI/CD Catalog. It's available on every tier.

Where do component files go?

In a top-level templates/ directory: either a single file such as templates/secret-detection.yml, or a folder with a template.yml such as templates/secret-detection/template.yml. Only template.yml is used by other projects; other files in that folder aren't released with the component.

How do I pin a component version?

Put a commit SHA, tag or branch after the @. A commit SHA beats a tag of the same name, and a tag beats a branch. For catalog components you can also use a partial version such as 1 or 1.2, or ~latest; partial versions never pick pre-releases. GitLab's security guidance prefers pinning to a commit SHA.

Why does ~latest fail with "content not found"?

~latest and partial versions only resolve against versions published in the CI/CD Catalog. If the catalog project has no published release yet, the include fails with "Component ... - content not found". Create a new release to fix it.

Can I use a GitLab.com component on GitLab Self-Managed?

Not directly: include:component only references components on the same instance. On Premium or Ultimate you mirror the GitLab.com component project into your instance, add a project description, mark it as a catalog resource, and run a tag pipeline to publish a release.

Sources

Checked against these pages on 22 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.

Do this from your phone with MergeBell

Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.

Get MergeBell for iPhoneGet MergeBell for Android

On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.