Agents gitlab-cicd
Expert-level guidance for GitLab CI/CD pipeline configuration, development, optimization, debugging, and best practices.
git clone https://github.com/aRustyDev/agents
T=$(mktemp -d) && git clone --depth=1 https://github.com/aRustyDev/agents "$T" && mkdir -p ~/.claude/skills && cp -r "$T/content/skills/gitlab-cicd" ~/.claude/skills/arustydev-agents-gitlab-cicd && rm -rf "$T"
content/skills/gitlab-cicd/SKILL.mdGitLab CI/CD
Expert-level guidance for GitLab CI/CD pipeline configuration, development, optimization, debugging, and best practices. Covers GitLab 9.0 through 18.x with version-specific annotations.
When to Use This Skill
- Configuring or modifying
files.gitlab-ci.yml - Debugging pipeline failures or unexpected job behavior
- Optimizing pipeline performance and compute minutes
- Setting up CI/CD components and include templates
- Managing runner infrastructure and autoscaling
- Implementing deployment strategies and environment lifecycle
- Configuring secrets, security scanning, and compliance
- Implementing semantic-release automation
Do Not Use This Skill When
- Working with GitHub Actions or other non-GitLab CI systems
- Managing GitLab instance administration (not CI/CD pipeline config)
- Writing application code unrelated to CI/CD
Quick Reference — Top 20 Keywords
| Keyword | Purpose | Detail |
|---|---|---|
| Commands to execute in a job | Required for every job unless is used |
| Conditional job inclusion | Replaces deprecated . See rules-patterns |
| DAG dependency declaration | Jobs run as soon as dependencies finish, ignoring stage order |
| Define CI/CD variables | Scoped to job, pipeline, or global. See variable scopes |
| Import external YAML | Types: , , , , |
| Inherit from hidden jobs | Up to 11 levels deep; merged with job config |
| Persist files between jobs | Use for content-addressable caching |
| Pass files between stages | , , access control. See artifacts |
| Docker image for job | Set globally via or per-job |
| Sidecar containers | Common: , database services for testing |
| Ordered execution groups | Jobs in same stage run in parallel by default |
| Pipeline-level rules | Controls whether pipeline is created. See workflow-rules |
| Start downstream pipeline | Parent-child (same project) or multi-project |
| Deployment target | Tiers, , . See environments |
| Global job defaults | , , , |
| Fan-out job execution | or for combinations |
| Auto-retry on failure | for selective retry. See retry |
| Job execution condition | , , , , |
| Concurrency control | Ensures only one job per group runs at a time |
| Allow auto-cancel | Set on non-deployment jobs for pipeline efficiency |
Quick Reference — Top 10 Predefined Variables
| Variable | Value | Available |
|---|---|---|
| Branch or tag name | Always |
| Full commit SHA | Always |
| Trigger type (, , , , ) | Always |
| Workspace directory path | Job only |
| Auto-generated token for API calls | Job only |
| Container registry path | Always |
| MR internal ID | MR pipelines only |
| MR source branch | MR pipelines only |
| Current environment name | Deployment jobs only |
| Branch name (not set for tags) | Branch pipelines only |
For the complete 170+ variable reference, see predefined variables.
Quick-Start Example
# Minimal pipeline — see references/ for each topic stages: [build, test, deploy] # → types-and-triggers.md variables: # → variables/definition.md NODE_VERSION: "20" default: image: node:${NODE_VERSION} cache: # → jobs/caching.md key: files: [package-lock.json] paths: [node_modules/] build: stage: build script: - npm ci - npm run build artifacts: # → jobs/artifacts.md paths: [dist/] expire_in: 1 week test: stage: test script: npm test coverage: '/Statements\s*:\s*(\d+\.?\d*)%/' # → jobs/testing.md needs: [build] # → jobs/execution-flow.md deploy: stage: deploy script: ./deploy.sh environment: # → pipelines/environments.md name: production rules: # → yaml/rules-patterns.md - if: $CI_COMMIT_BRANCH == "main" when: manual needs: [test]
Pipeline Configuration
GitLab supports multiple pipeline types with distinct triggering rules and variable availability.
| Pipeline Type | Trigger | Key Variable |
|---|---|---|
| Branch pipeline | Push to branch | |
| Tag pipeline | Push tag | |
| MR pipeline | MR created/updated | |
| Merged results | MR with merged results enabled | |
| Merge train | MR added to merge train | |
| Scheduled | Cron schedule triggers | |
| Parent-child | | |
| Multi-project | | |
Key gotcha:
CI_MERGE_REQUEST_* variables are only available when CI_PIPELINE_SOURCE=merge_request_event. Use workflow:rules to prevent duplicate branch+MR pipelines.
References:
- Pipeline Types & Triggers
- Merge Request Pipelines — detached, merged results, merge trains, fork handling
- Downstream Pipelines — parent-child, multi-project, dynamic child
- Monorepo Strategies —
, per-service child pipelinesrules:changes - Pipeline Optimization — DAG, parallelism, compute minutes
- Scheduled Pipelines — cron syntax, schedule-only patterns
- Manual Gates —
, approvals, deploy freezeswhen:manual - Cross-Project Pipelines — multi-project triggers, artifact sharing
- Notifications & Badges — pipeline badges, email/Slack integration
YAML Authoring
Pipeline YAML supports composition patterns for DRY, maintainable configurations.
| Pattern | Mechanism | Scope |
|---|---|---|
| Job inheritance (11-level deep merge) | Same file or included files |
YAML anchors (/) | Same-file reference | Single file only |
| Cross-file array extraction | Included files (GitLab 13.0+) |
| External YAML import | local, project, remote, template, component |
Key gotcha: YAML anchors do NOT work across
include boundaries — use extends or !reference instead.
References:
- Keyword Reference — full .gitlab-ci.yml keyword documentation
- Rules Patterns —
,rules:if
,rules:changesrules:exists - YAML Composition — anchors, extends,
, merge keys!reference - Workflow Rules —
,workflow:rules
, namingauto_cancel - YAML Optimization — DRY pipeline design patterns
Variables
Variables follow an 11-level precedence hierarchy — knowing the order prevents hours of debugging.
Precedence (highest → lowest):
- Pipeline execution policy variables
- Scan execution policy variables
- Pipeline variables (trigger, scheduled, manual, API)
- Project variables (UI/API)
- Group variables (inherited, closest subgroup wins)
- Instance variables
report variablesdotenv- Job-level YAML
variables: - Default (global) YAML
variables: - Deployment variables
- Predefined variables
Note:
elevates parent YAML variables to pipeline variable precedence (level 3) in downstream pipelines. It is a mechanism, not a separate precedence level.trigger:forward:pipeline_variables: true
Key gotcha: Variables defined in
rules:variables override job-level variables but only when that rule matches.
References:
- Predefined Variables — 170+ variables by category and version
- Variable Precedence — 11-level hierarchy with override examples
- Masking & Protection — masking rules, ≥8 chars, protected scoping
- Variable Scopes — expansion in rules vs script vs services
- Variable Definition — YAML, UI, API,
,optionsdescription
Jobs & Execution
| Feature | Keyword | Key Detail |
|---|---|---|
| DAG execution | | Up to 50 dependencies; ignores stage ordering |
| Parallel fan-out | | Generates N×M jobs from variable combinations |
| Concurrency lock | | Only one job per group runs at a time |
| Test reporting | | Parses JUnit XML into MR widgets |
| Coverage | | Extracted from job log for MR display |
| Container builds | | Or use Kaniko/Buildah for rootless builds |
Key gotcha:
cache is for speed (may miss); artifacts are for correctness (guaranteed). Don't use cache to pass build outputs between jobs — use artifacts.
References:
- Testing Strategies — JUnit, coverage, quality reports
- Caching —
, fallback_keys, distributed cachecache:key:files - Artifacts —
,expire_in
, cross-pipeline sharingexpose_as - Execution Flow —
,needs:
, DAG patternsdependencies - Docker Builds — DinD, Kaniko, Buildah, multi-stage
- Git Strategies —
,GIT_STRATEGY
, submodulesGIT_DEPTH - Retry & Resilience —
,retry:when
, timeoutallow_failure
Runner Infrastructure
Runners execute jobs. Executor choice determines security model, performance, and isolation.
| Executor | Isolation | Best For | Autoscalable |
|---|---|---|---|
| Docker | Container | Most CI jobs | Yes (docker-autoscaler) |
| Kubernetes | Pod | Cloud-native, multi-container | Yes (native) |
| Shell | None | Simple scripts, host access | No |
| Docker Autoscaler | VM + Container | Cost-optimized cloud fleets | Yes |
| Instance | VM | Full isolation | Yes (fleeting) |
| VirtualBox | VM | Legacy, local testing | Yes (legacy) |
Key gotcha: Docker-in-Docker (
dind) requires privileged: true — significant security risk. Prefer Kaniko for container builds when possible.
References:
- Runner Architecture — manager model, executor types, compatibility
- Executors — Docker, K8s, shell config and comparison
- Autoscaling — docker-autoscaler, fleeting, scaling policies
- Runner Security — tokens,
, hardeningallowed_images - Performance —
,concurrent
, tuningcheck_interval - Fleet Management — config.toml, Prometheus metrics
CI/CD Components
Components are reusable pipeline building blocks published to the CI/CD Catalog (GitLab 17.0+).
include: - component: $CI_SERVER_FQDN/my-org/my-component@1.2.0 inputs: stage: test scan_level: full
Key gotcha: Always pin component versions (
@1.2.0 or @1 for major). Unpinned components are a supply-chain risk.
References:
- Component Authoring — project structure,
, Catalogspec:inputs - Catalog — discovery, version pinning, evaluation
- Inputs — types, validation, defaults
- Testing — self-referencing, integration tests
- Security — pinning audit,
include:integrity
Semantic Release
Automated versioning with
@semantic-release/gitlab and the to-be-continuous component.
Token setup: Requires
GITLAB_TOKEN (project access token with api scope) or GL_TOKEN. Must be masked and protected.
Key gotcha: Set
GIT_DEPTH: 0 in the release job — shallow clones break commit analysis.
References:
- GitLab Integration — plugin lifecycle, TBC, tokens
- Configuration —
, presets, hooks, GPG.releaserc - Testing — dry-run, verification
Deployment & Environments
| Strategy | Pattern | Risk | Rollback |
|---|---|---|---|
| Rolling | Replace instances incrementally | Medium | Redeploy previous version |
| Blue-Green | Switch traffic between environments | Low | Switch back |
| Canary | Route % of traffic to new version | Low | Reduce to 0% |
| Feature Flags | Toggle features in-app | Lowest | Disable flag |
Key gotcha: Always set
auto_stop_in on dynamic environments. Without it, review apps accumulate and leak resources.
References:
- Deployment Strategies — blue-green, canary, rolling, feature flags
- Dynamic Environments — review apps, auto_stop, cleanup
- Infrastructure as Code — Terraform/OpenTofu, state
- Release Automation — changelog, orchestration
Security
| Feature | Keywords/Config | GitLab Tier |
|---|---|---|
| Secret variables | (masked + protected) | Free |
| Vault integration | | Premium |
| OIDC/JWT auth | | Free (15.7+) |
| SAST | | Ultimate |
| Dependency scanning | | Ultimate |
| Container scanning | | Ultimate |
| Compliance frameworks | Project settings | Ultimate |
Key gotcha:
CI_JOB_TOKEN default scope allows access to all reachable projects. Restrict it via Settings > CI/CD > Token Access.
References:
- Secrets Management — Vault, GCP, Azure, AWS, OIDC
- Security Scanning — SAST, DAST, container, dependency
- Compliance — frameworks, audit trails, governance
- Pipeline Security — CI_JOB_TOKEN scoping, protected runners, fork safety
Troubleshooting
Debugging decision tree:
- YAML syntax error? → Use Pipeline Editor or CI Lint API
- Job not starting? → Check
evaluation — View "merged YAML" in Pipeline Editorrules: - Variable not expanding? → Check scopes and precedence
- Cache miss? → Verify
matches — check runner cache backendcache:key - Artifact not found? → Check
,expire_in
, anddependencies:needs:artifacts: - Runner issues? → Check tags, runner availability, executor config
- Need verbose output? → Set
(⚠️ exposes secrets)CI_DEBUG_TRACE=true
References:
- Troubleshooting Guide — editor, lint, debug trace, common errors
- FAQ & Gotchas — top 25+ categorized gotchas with fixes
Output Formats
When producing specific types of analysis, use the corresponding output format spec:
| Task | Output Style |
|---|---|
| Analyzing MegaLinter results | megalinter-analysis |
| Debugging pipeline failures | troubleshooting-report |
| Reviewing test results | ci-tester-report |
| Reviewing pipeline architecture | ci-architecture-review |
Version Compatibility
Key feature introductions across GitLab versions:
| Version | Feature | Impact |
|---|---|---|
| 12.5 | | Pipeline-level conditional creation |
| 13.0 | tag | Cross-file YAML references |
| 15.3 | | Baseline comparison for (GA 16.0) |
| 13.9 | cross-stage | DAG dependencies across stages |
| 14.2 | | Conditional file includes |
| 15.0 | | SHA-pinned includes for supply chain security |
| 15.1 | executor | Modern runner autoscaling (replaces docker+machine) |
| 15.7 | | OIDC/JWT for external auth (Vault, cloud providers) |
| 16.0 | beta | Reusable pipeline building blocks |
| 16.3 | | Dynamic pipeline naming |
| 16.6 | | Fan-in from matrix jobs |
| 17.0 | CI/CD Catalog GA | Component discovery and versioning |
| 17.2 | | Custom git clone flags + native clone FF |
| 17.4 | | Pass inputs to any included file |
| 18.0 | keyword | CI Steps (experimental) — replaces model |
Related Resources
- GitLab CI/CD Documentation
- .gitlab-ci.yml Reference
- Predefined Variables
- CI/CD Component Catalog
- GitLab Runner Documentation
Workspace Examples
Annotated analyses of real pipelines from this workspace:
- MAP Terragrunt Pipeline — component includes, MegaLinter, release automation
- Component Include Patterns — template structure,
usagespec:inputs