Develop reusable GitLab CI/CD components and templates. Use when creating CI/CD component libraries, building include templates, packaging components for the CI/CD Catalog, or designing organization-wide pipeline templates.
Develop reusable GitLab CI/CD components and templates. Use when creating CI/CD component libraries, building include templates, packaging components for the CI/CD Catalog, or designing organization-wide pipeline templates.
GitLab CI/CD Components Development
Guide for developing reusable GitLab CI/CD components and templates that can be shared across projects and organizations.
When to Use This Skill
Creating reusable CI/CD component libraries
Building include templates for shared pipelines
Publishing to the GitLab CI/CD Catalog
Designing organization-wide pipeline standards
Packaging job templates and configurations
Understanding component inputs, outputs, and specs
Component Types
CI/CD Components (Catalog)
Modern, versioned components with defined interfaces:
spec:inputs:environments:type:arraydefault:-staging-production---# Generates multiple jobs from array.deploy-template:stage:deployscript:-./deploy.sh$ENVIRONMENTdeploy-staging:extends:.deploy-templatevariables:ENVIRONMENT:stagingrules:-if:$CI_COMMIT_BRANCH=="main"deploy-production:extends:.deploy-templatevariables:ENVIRONMENT:productionwhen:manualrules:-if:$CI_COMMIT_BRANCH=="main"
CI/CD Catalog Publishing
Project Configuration
# .gitlab-ci.yml in component projectstages:-test-releasetest-components:stage:testscript:-gitlab-ci-local--list# Validate componentscreate-release:stage:releasescript:-echo"Creating release"release:tag_name:$CI_COMMIT_TAGdescription:'Release $CI_COMMIT_TAG'rules:-if:$CI_COMMIT_TAG
Catalog Metadata
# In project settings or .gitlab/ci-component.yml---name:MyCI/CDComponentsdescription:ReusablecomponentsforCI/CDicon:🚀categories:-Build-Test-Deploy
Versioning
# Semantic versioning for components
git tag -a v1.0.0 -m "Initial release"
git push origin v1.0.0
# Install gitlab-ci-local
npm install -g gitlab-ci-local
# Test pipeline with components
gitlab-ci-local --list
gitlab-ci-local test
Advanced Patterns
Conditional Component Content
spec:inputs:enable-sast:type:booleandefault:false---build:stage:buildscript:-npmrunbuild# Only included when enable-sast is truesast-scan:rules:-if:$[[inputs.enable-sast]]stage:testscript:-npmaudit
Composition of Components
# meta-component that combines othersspec:inputs:nodejs-version:default:'20'run-security:type:booleandefault:true---include:-component:gitlab.com/org/components/nodejs-setup@1.0inputs:version:$[[inputs.nodejs-version]]-component:gitlab.com/org/components/security-scan@1.0rules:-if:$[[inputs.run-security]]
Dynamic Child Pipelines
spec:inputs:services:type:array---generate-pipeline:stage:buildscript:-|
cat > child-pipeline.yml << EOF
stages:
- deploy
EOF
for service in $[[ inputs.services | join(" ") ]]; do
cat >> child-pipeline.yml << EOF
deploy-$service:
stage: deploy
script:
- ./deploy.sh $service
EOF
done
artifacts:paths:-child-pipeline.ymltrigger-deploy:stage:deploytrigger:include:-artifact:child-pipeline.ymljob:generate-pipeline
Documentation
Component README
# Component Name
Brief description of what this component does.
## Usage
\`\`\`yaml
include:
- component: gitlab.com/org/my-component@1.0.0
inputs:
param1: value1
\`\`\`
## Inputs
| Input | Type | Default | Description |
|-------|------|---------|-------------|
| `param1` | string | `default` | What it does |
| `enable-x` | boolean | `true` | Whether to enable X |
## Examples### Basic Usage
\`\`\`yaml
include:
- component: gitlab.com/org/my-component@1.0.0
\`\`\`
### Advanced Usage
\`\`\`yaml
include:
- component: gitlab.com/org/my-component@1.0.0
inputs:
param1: custom-value
enable-x: false
\`\`\`
## Outputs
This component creates the following jobs:
-`build`: Builds the application
-`test`: Runs tests