A CI/CD component is a reusable single pipeline configuration unit. Use components
to create a small part of a larger pipeline, or even to compose a complete pipeline configuration.
A component can be configured with
input parameters
for more
dynamic behavior.
A component project is a GitLab project with a repository that hosts one or more components.
All components in the project are versioned together, with a maximum of 30 components per project.
If a component requires different versioning from other components, the component should be moved
to a dedicated component project.
In this example:
$CI_SERVER_FQDN is a predefined variable
for the fully qualified domain name (FQDN) matching the GitLab host.
You can only reference components in the same GitLab instance as your project.
my-org/security-components is the full path of the project containing the component.
secret-detection is the component name that is defined as either a single file templates/secret-detection.yml
or as a directory templates/secret-detection/ containing a template.yml.
1.0.0 is the version of the component.
When GitLab creates a new pipeline, the component’s configuration is fetched and added to
the pipeline’s configuration.
If a component requires the use of tokens, passwords, or other sensitive data to function,
be sure to audit the component’s source code to verify that the data is only used to
perform actions that you expect and authorize. You should also use tokens and secrets
with the minimum permissions, access, or scope required to complete the action.
A branch name, for example main. If a branch and tag exist with the same name,
the tag takes precedence over the branch.
~latest, which always points to the latest semantic version
published in the CI/CD Catalog. Use ~latest only if you want to use the absolute
latest version at all times, which could include breaking changes. ~latest
does not include pre-releases, for example 1.0.1-rc, which are not considered
production-ready.
You can use any version supported by the component, but using a version published
to the CI/CD catalog is recommended. The version referenced with a commit SHA or branch name
might not be published in the CI/CD catalog, but could be used for testing.
A minor version, use both the major and minor version numbers in the reference,
but not the patch version number. For example, use 1.1 to use the latest version
that starts with 1.1, including 1.1.0 or 1.1.9, but not 1.2.0.
A major version, use only the major version number in the reference. For example,
use 1 to use the latest version that starts with 1., like 1.0.0 or 1.9.9,
but not 2.0.0.
All versions, use ~latest to use the latest released version.
For example, a component is released in this exact order:
1.0.0
1.1.0
2.0.0
1.1.1
1.2.0
2.1.0
2.0.1
In this example, referencing the component with:
1 would use the 1.2.0 version.
1.1 would use the 1.1.1 version.
~latest would use the 2.1.0 version.
Pre-release versions are never fetched when referencing a version range. To fetch
a pre-release version, specify the full version, for example 1.0.1-rc.
When depending on components from other projects, pin their version to a release from the catalog rather than using moving target
versions such as ~latest or a Git reference. Using a release or Git SHA guarantees that you are fetching the same revision
all the time and that consumers of your component get consistent behavior.
Update your dependencies regularly by pinning them to newer releases. Then publish a new release of your components with updated
dependencies.
Add a ## Components section with sub-sections like ### Component A for each component in the project.
In each component section:
Add a description of what the component does.
Add at least one YAML example showing how to use it.
If the component uses inputs, add a table showing all inputs with name, description, type, and default value.
If the component uses any variables or secrets, those should be documented too.
A ## Contribute section is recommended if contributions are welcome.
If a component needs more instructions, add additional documentation in a Markdown file
in the component directory and link to it from the main README.md file. For example:
README.md # with links to the specific docs.md
templates/
├── component-1/
│ ├── template.yml
│ └── docs.md
└── component-2/
├── template.yml
└── docs.md
include:# include the component located in the current project from the current SHA-component:$CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHAinputs:stage:buildstages:[build,test,release]# Check if `component job of my-component` is added.# This example job could also test that the included component works as expected.# You can inspect data generated by the component, use GitLab API endpoints, or third-party tools.ensure-job-added:stage:testimage:badouralix/curl-jq# Replace "component job of my-component" with the job name in your component.script:route="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs"count=`curl --silent "$route" | jq 'map(select(.name | contains("component job of my-component"))) | length'`if [ "$count" != "1" ]; thenexit 1; elseecho "Component Job present"# If the pipeline is for a new tag with a semantic version, and all previous jobs succeed,# create the release.create-release:stage:releaseimage:registry.gitlab.com/gitlab-org/release-cli:latestscript:echo "Creating release $CI_COMMIT_TAG"rules:-if:$CI_COMMIT_TAGrelease:tag_name:$CI_COMMIT_TAGdescription:"Release$CI_COMMIT_TAGofcomponentsrepository$CI_PROJECT_PATH"
After committing and pushing changes, the pipeline tests the component, then creates
a release if the earlier jobs pass.
Authentication is necessary if the project is private.
Avoid hard-coding instance or project-specific values
When using another component in your component, use $CI_SERVER_FQDN
instead of your instance’s Fully Qualified Domain Name (like gitlab.com).
When accessing the GitLab API in your component, use the $CI_API_V4_URL instead of the
full URL and path for your instance (like https://gitlab.com/api/v4).
It’s important that an access token can optionally be provided via inputs or variables to
authenticate requests on self-managed instances.
Avoid using global keywords
Avoid using global keywords in a component.
Using these keywords in a component affects all jobs in a pipeline, including jobs
directly defined in the main .gitlab-ci.yml or in other included components.
As an alternative to global keywords:
Add the configuration directly to each job, even if it creates some duplication
in the component configuration.
Use the extends keyword in the component, but use
unique names that reduce the risk of naming conflicts when the component is merged
into the configuration.
For example, avoid using the default global keyword:
# Not recommendeddefault:image:ruby:3.0rspec-1:script:bundle exec rspec dir1/rspec-2:script:bundle exec rspec dir2/
CI/CD components can be used without being listed in the CI/CD catalog.
However, publishing a component’s releases in the catalog makes it discoverable to other users.
Prerequisites:
You must have at least the Maintainer role for the project.
To publish a new version of the component to the catalog:
Add a job to the project’s .gitlab-ci.yml file that uses the release
keyword to create the new release when a tag is created.
You should configure the tag pipeline to test the components before
running the release job. For example:
Create a new tag for the release,
which should trigger a tag pipeline that contains the job responsible for creating the release.
The tag must use semantic versioning.
After the release job completes successfully, the release is created and the new version
is published to the CI/CD catalog.
This action destroys the metadata about the component project and its versions published
in the catalog. The project and its repository still exist, but are not visible in the catalog.
To publish the component project in the catalog again, you need to publish a new release.
This GitLab CI configuration is invalid: Component 'gitlab.com/my-namespace/my-project/my-component@~latest' - content not found
The ~latest behavior was updated
in GitLab 16.10. It now refers to the latest semantic version of the catalog resource. To resolve this issue, create a new release.
to fix an error or add an improvement in a merge request. Create an issue
to suggest an improvement to this page.
View pricing
to see all GitLab tiers and features, or to upgrade. Try GitLab for free
with access to all features for 30 days. search the docs.
If you want help with something specific and could use community support,
post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab
subscription). Request support