GitLab 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
.gitlab-ci.yml files
- 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 |
script |
Commands to execute in a job |
Required for every job unless trigger is used |
rules |
Conditional job inclusion |
Replaces deprecated only/except. See rules-patterns |
needs |
DAG dependency declaration |
Jobs run as soon as dependencies finish, ignoring stage order |
variables |
Define CI/CD variables |
Scoped to job, pipeline, or global. See variable scopes |
include |
Import external YAML |
Types: local, project, remote, template, component |
extends |
Inherit from hidden jobs |
Up to 11 levels deep; merged with job config |
cache |
Persist files between jobs |
Use cache:key:files for content-addressable caching |
artifacts |
Pass files between stages |
expire_in, expose_as, access control. See artifacts |
image |
Docker image for job |
Set globally via default:image or per-job |
services |
Sidecar containers |
Common: docker:dind, database services for testing |
stages |
Ordered execution groups |
Jobs in same stage run in parallel by default |
workflow |
Pipeline-level rules |
Controls whether pipeline is created. See workflow-rules |
trigger |
Start downstream pipeline |
Parent-child (same project) or multi-project |
environment |
Deployment target |
Tiers, auto_stop_in, on_stop. See environments |
default |
Global job defaults |
image, before_script, retry, interruptible |
parallel |
Fan-out job execution |
parallel: N or parallel:matrix for combinations |
retry |
Auto-retry on failure |
retry:when for selective retry. See retry |
when |
Job execution condition |
on_success, on_failure, always, manual, delayed |
resource_group |
Concurrency control |
Ensures only one job per group runs at a time |
interruptible |
Allow auto-cancel |
Set true on non-deployment jobs for pipeline efficiency |
Quick Reference — Top 10 Predefined Variables
| Variable |
Value |
Available |
CI_COMMIT_REF_NAME |
Branch or tag name |
Always |
CI_COMMIT_SHA |
Full commit SHA |
Always |
CI_PIPELINE_SOURCE |
Trigger type (push, merge_request_event, schedule, api, trigger) |
Always |
CI_PROJECT_DIR |
Workspace directory path |
Job only |
CI_JOB_TOKEN |
Auto-generated token for API calls |
Job only |
CI_REGISTRY_IMAGE |
Container registry path |
Always |
CI_MERGE_REQUEST_IID |
MR internal ID |
MR pipelines only |
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME |
MR source branch |
MR pipelines only |
CI_ENVIRONMENT_NAME |
Current environment name |
Deployment jobs only |
CI_COMMIT_BRANCH |
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 |
CI_COMMIT_BRANCH |
| Tag pipeline |
Push tag |
CI_COMMIT_TAG |
| MR pipeline |
MR created/updated |
CI_MERGE_REQUEST_IID |
| Merged results |
MR with merged results enabled |
CI_MERGE_REQUEST_EVENT_TYPE=merged_result |
| Merge train |
MR added to merge train |
CI_MERGE_REQUEST_EVENT_TYPE=merge_train |
| Scheduled |
Cron schedule triggers |
CI_PIPELINE_SOURCE=schedule |
| Parent-child |
trigger:include |
CI_PIPELINE_SOURCE=parent_pipeline |
| Multi-project |
trigger:project |
CI_PIPELINE_SOURCE=pipeline |
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 —
rules:changes, per-service child pipelines
- Pipeline Optimization — DAG, parallelism, compute minutes
- Scheduled Pipelines — cron syntax, schedule-only patterns
- Manual Gates —
when:manual, approvals, deploy freezes
- 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 |
extends |
Job inheritance (11-level deep merge) |
Same file or included files |
YAML anchors (&/*) |
Same-file reference |
Single file only |
!reference |
Cross-file array extraction |
Included files (GitLab 13.0+) |
include |
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:changes, rules:exists
- YAML Composition — anchors, extends,
!reference, merge keys
- Workflow Rules —
workflow:rules, auto_cancel, naming
- 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
dotenv report variables
- Job-level YAML
variables:
- Default (global) YAML
variables:
- Deployment variables
- Predefined variables
Note: trigger:forward:pipeline_variables: true elevates parent YAML variables to pipeline variable precedence (level 3) in downstream pipelines. It is a mechanism, not a separate precedence level.
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,
options, description
Jobs & Execution
| Feature |
Keyword |
Key Detail |
| DAG execution |
needs: |
Up to 50 dependencies; ignores stage ordering |
| Parallel fan-out |
parallel:matrix: |
Generates N×M jobs from variable combinations |
| Concurrency lock |
resource_group: |
Only one job per group runs at a time |
| Test reporting |
artifacts:reports:junit: |
Parses JUnit XML into MR widgets |
| Coverage |
coverage: '/regex/' |
Extracted from job log for MR display |
| Container builds |
services: [docker:dind] |
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 —
cache:key:files, fallback_keys, distributed cache
- Artifacts —
expire_in, expose_as, cross-pipeline sharing
- Execution Flow —
needs:, dependencies, DAG patterns
- Docker Builds — DinD, Kaniko, Buildah, multi-stage
- Git Strategies —
GIT_STRATEGY, GIT_DEPTH, submodules
- Retry & Resilience —
retry:when, allow_failure, timeout
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,
allowed_images, hardening
- Performance —
concurrent, check_interval, tuning
- 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,
spec:inputs, Catalog
- 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 —
.releaserc, presets, hooks, GPG
- 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 |
Settings > CI/CD > Variables (masked + protected) |
Free |
| Vault integration |
secrets:vault: |
Premium |
| OIDC/JWT auth |
id_tokens: |
Free (15.7+) |
| SAST |
include: SAST.gitlab-ci.yml |
Ultimate |
| Dependency scanning |
include: Dependency-Scanning.gitlab-ci.yml |
Ultimate |
| Container scanning |
include: Container-Scanning.gitlab-ci.yml |
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
rules: evaluation — View "merged YAML" in Pipeline Editor
- Variable not expanding? → Check scopes and precedence
- Cache miss? → Verify
cache:key matches — check runner cache backend
- Artifact not found? → Check
expire_in, dependencies:, and needs:artifacts:
- Runner issues? → Check tags, runner availability, executor config
- Need verbose output? → Set
CI_DEBUG_TRACE=true (⚠️ exposes secrets)
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 |
workflow:rules |
Pipeline-level conditional creation |
| 13.0 |
!reference tag |
Cross-file YAML references |
| 15.3 |
rules:changes:compare_to |
Baseline comparison for rules:changes (GA 16.0) |
| 13.9 |
needs: cross-stage |
DAG dependencies across stages |
| 14.2 |
include:rules |
Conditional file includes |
| 15.0 |
include:integrity |
SHA-pinned includes for supply chain security |
| 15.1 |
docker-autoscaler executor |
Modern runner autoscaling (replaces docker+machine) |
| 15.7 |
id_tokens: |
OIDC/JWT for external auth (Vault, cloud providers) |
| 16.0 |
CI/CD Components beta |
Reusable pipeline building blocks |
| 16.3 |
workflow:name |
Dynamic pipeline naming |
| 16.6 |
needs:parallel:matrix |
Fan-in from matrix jobs |
| 17.0 |
CI/CD Catalog GA |
Component discovery and versioning |
| 17.2 |
GIT_CLONE_EXTRA_FLAGS |
Custom git clone flags + native clone FF |
| 17.4 |
include:inputs |
Pass inputs to any included file |
| 18.0 |
run: keyword |
CI Steps (experimental) — replaces script: model |
Related Resources
Workspace Examples
Annotated analyses of real pipelines from this workspace:
- MAP Terragrunt Pipeline — component includes, MegaLinter, release automation
- Component Include Patterns — template structure,
spec:inputs usage
1---2name: gitlab-cicd3description: Expert-level guidance for GitLab CI/CD pipeline configuration, development, optimization, debugging, and best practices.4---56# GitLab CI/CD78Expert-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.910## When to Use This Skill1112- Configuring or modifying `.gitlab-ci.yml` files13- Debugging pipeline failures or unexpected job behavior14- Optimizing pipeline performance and compute minutes15- Setting up CI/CD components and include templates16- Managing runner infrastructure and autoscaling17- Implementing deployment strategies and environment lifecycle18- Configuring secrets, security scanning, and compliance19- Implementing semantic-release automation2021## Do Not Use This Skill When2223- Working with **GitHub Actions** or other non-GitLab CI systems24- Managing **GitLab instance administration** (not CI/CD pipeline config)25- Writing application code unrelated to CI/CD2627---2829## Quick Reference — Top 20 Keywords3031| Keyword | Purpose | Detail |32|---------|---------|--------|33| `script` | Commands to execute in a job | Required for every job unless `trigger` is used |34| `rules` | Conditional job inclusion | Replaces deprecated `only/except`. See [rules-patterns](references/yaml/rules-patterns.md) |35| `needs` | DAG dependency declaration | Jobs run as soon as dependencies finish, ignoring stage order |36| `variables` | Define CI/CD variables | Scoped to job, pipeline, or global. See [variable scopes](references/variables/scopes.md) |37| `include` | Import external YAML | Types: `local`, `project`, `remote`, `template`, `component` |38| `extends` | Inherit from hidden jobs | Up to 11 levels deep; merged with job config |39| `cache` | Persist files between jobs | Use `cache:key:files` for content-addressable caching |40| `artifacts` | Pass files between stages | `expire_in`, `expose_as`, access control. See [artifacts](references/jobs/artifacts.md) |41| `image` | Docker image for job | Set globally via `default:image` or per-job |42| `services` | Sidecar containers | Common: `docker:dind`, database services for testing |43| `stages` | Ordered execution groups | Jobs in same stage run in parallel by default |44| `workflow` | Pipeline-level rules | Controls whether pipeline is created. See [workflow-rules](references/yaml/workflow-rules.md) |45| `trigger` | Start downstream pipeline | Parent-child (same project) or multi-project |46| `environment` | Deployment target | Tiers, `auto_stop_in`, `on_stop`. See [environments](references/pipelines/environments.md) |47| `default` | Global job defaults | `image`, `before_script`, `retry`, `interruptible` |48| `parallel` | Fan-out job execution | `parallel: N` or `parallel:matrix` for combinations |49| `retry` | Auto-retry on failure | `retry:when` for selective retry. See [retry](references/jobs/retry-resilience.md) |50| `when` | Job execution condition | `on_success`, `on_failure`, `always`, `manual`, `delayed` |51| `resource_group` | Concurrency control | Ensures only one job per group runs at a time |52| `interruptible` | Allow auto-cancel | Set `true` on non-deployment jobs for pipeline efficiency |5354## Quick Reference — Top 10 Predefined Variables5556| Variable | Value | Available |57|----------|-------|-----------|58| `CI_COMMIT_REF_NAME` | Branch or tag name | Always |59| `CI_COMMIT_SHA` | Full commit SHA | Always |60| `CI_PIPELINE_SOURCE` | Trigger type (`push`, `merge_request_event`, `schedule`, `api`, `trigger`) | Always |61| `CI_PROJECT_DIR` | Workspace directory path | Job only |62| `CI_JOB_TOKEN` | Auto-generated token for API calls | Job only |63| `CI_REGISTRY_IMAGE` | Container registry path | Always |64| `CI_MERGE_REQUEST_IID` | MR internal ID | MR pipelines only |65| `CI_MERGE_REQUEST_SOURCE_BRANCH_NAME` | MR source branch | MR pipelines only |66| `CI_ENVIRONMENT_NAME` | Current environment name | Deployment jobs only |67| `CI_COMMIT_BRANCH` | Branch name (not set for tags) | Branch pipelines only |6869For the complete 170+ variable reference, see [predefined variables](references/variables/predefined.md).7071---7273## Quick-Start Example7475```yaml76# Minimal pipeline — see references/ for each topic77stages: [build, test, deploy] # → types-and-triggers.md7879variables: # → variables/definition.md80 NODE_VERSION: "20"8182default:83 image: node:${NODE_VERSION}84 cache: # → jobs/caching.md85 key:86 files: [package-lock.json]87 paths: [node_modules/]8889build:90 stage: build91 script:92 - npm ci93 - npm run build94 artifacts: # → jobs/artifacts.md95 paths: [dist/]96 expire_in: 1 week9798test:99 stage: test100 script: npm test101 coverage: '/Statements\s*:\s*(\d+\.?\d*)%/' # → jobs/testing.md102 needs: [build] # → jobs/execution-flow.md103104deploy:105 stage: deploy106 script: ./deploy.sh107 environment: # → pipelines/environments.md108 name: production109 rules: # → yaml/rules-patterns.md110 - if: $CI_COMMIT_BRANCH == "main"111 when: manual112 needs: [test]113```114115---116117## Pipeline Configuration118119GitLab supports multiple pipeline types with distinct triggering rules and variable availability.120121| Pipeline Type | Trigger | Key Variable |122|---------------|---------|--------------|123| Branch pipeline | Push to branch | `CI_COMMIT_BRANCH` |124| Tag pipeline | Push tag | `CI_COMMIT_TAG` |125| MR pipeline | MR created/updated | `CI_MERGE_REQUEST_IID` |126| Merged results | MR with merged results enabled | `CI_MERGE_REQUEST_EVENT_TYPE=merged_result` |127| Merge train | MR added to merge train | `CI_MERGE_REQUEST_EVENT_TYPE=merge_train` |128| Scheduled | Cron schedule triggers | `CI_PIPELINE_SOURCE=schedule` |129| Parent-child | `trigger:include` | `CI_PIPELINE_SOURCE=parent_pipeline` |130| Multi-project | `trigger:project` | `CI_PIPELINE_SOURCE=pipeline` |131132**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.133134**References:**135- [Pipeline Types & Triggers](references/pipelines/types-and-triggers.md)136- [Merge Request Pipelines](references/pipelines/merge-request.md) — detached, merged results, merge trains, fork handling137- [Downstream Pipelines](references/pipelines/downstream.md) — parent-child, multi-project, dynamic child138- [Monorepo Strategies](references/pipelines/monorepo.md) — `rules:changes`, per-service child pipelines139- [Pipeline Optimization](references/pipelines/optimization.md) — DAG, parallelism, compute minutes140- [Scheduled Pipelines](references/pipelines/scheduling.md) — cron syntax, schedule-only patterns141- [Manual Gates](references/pipelines/manual-gates.md) — `when:manual`, approvals, deploy freezes142- [Cross-Project Pipelines](references/integrations/cross-project.md) — multi-project triggers, artifact sharing143- [Notifications & Badges](references/integrations/notifications.md) — pipeline badges, email/Slack integration144145---146147## YAML Authoring148149Pipeline YAML supports composition patterns for DRY, maintainable configurations.150151| Pattern | Mechanism | Scope |152|---------|-----------|-------|153| `extends` | Job inheritance (11-level deep merge) | Same file or included files |154| YAML anchors (`&`/`*`) | Same-file reference | Single file only |155| `!reference` | Cross-file array extraction | Included files (GitLab 13.0+) |156| `include` | External YAML import | local, project, remote, template, component |157158**Key gotcha:** YAML anchors do NOT work across `include` boundaries — use `extends` or `!reference` instead.159160**References:**161- [Keyword Reference](references/yaml/keyword-reference.md) — full .gitlab-ci.yml keyword documentation162- [Rules Patterns](references/yaml/rules-patterns.md) — `rules:if`, `rules:changes`, `rules:exists`163- [YAML Composition](references/yaml/yaml-composition.md) — anchors, extends, `!reference`, merge keys164- [Workflow Rules](references/yaml/workflow-rules.md) — `workflow:rules`, `auto_cancel`, naming165- [YAML Optimization](references/pipelines/yaml-optimization.md) — DRY pipeline design patterns166167---168169## Variables170171Variables follow an **11-level precedence hierarchy** — knowing the order prevents hours of debugging.172173**Precedence (highest → lowest):**1741. Pipeline execution policy variables1752. Scan execution policy variables1763. Pipeline variables (trigger, scheduled, manual, API)1774. Project variables (UI/API)1785. Group variables (inherited, closest subgroup wins)1796. Instance variables1807. `dotenv` report variables1818. Job-level YAML `variables:`1829. Default (global) YAML `variables:`18310. Deployment variables18411. Predefined variables185186> **Note:** `trigger:forward:pipeline_variables: true` elevates parent YAML variables to pipeline variable precedence (level 3) in downstream pipelines. It is a mechanism, not a separate precedence level.187188**Key gotcha:** Variables defined in `rules:variables` override job-level variables but only when that rule matches.189190**References:**191- [Predefined Variables](references/variables/predefined.md) — 170+ variables by category and version192- [Variable Precedence](references/variables/precedence.md) — 11-level hierarchy with override examples193- [Masking & Protection](references/variables/masking-protection.md) — masking rules, ≥8 chars, protected scoping194- [Variable Scopes](references/variables/scopes.md) — expansion in rules vs script vs services195- [Variable Definition](references/variables/definition.md) — YAML, UI, API, `options`, `description`196197---198199## Jobs & Execution200201| Feature | Keyword | Key Detail |202|---------|---------|------------|203| DAG execution | `needs:` | Up to 50 dependencies; ignores stage ordering |204| Parallel fan-out | `parallel:matrix:` | Generates N×M jobs from variable combinations |205| Concurrency lock | `resource_group:` | Only one job per group runs at a time |206| Test reporting | `artifacts:reports:junit:` | Parses JUnit XML into MR widgets |207| Coverage | `coverage: '/regex/'` | Extracted from job log for MR display |208| Container builds | `services: [docker:dind]` | Or use Kaniko/Buildah for rootless builds |209210**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.211212**References:**213- [Testing Strategies](references/jobs/testing.md) — JUnit, coverage, quality reports214- [Caching](references/jobs/caching.md) — `cache:key:files`, fallback_keys, distributed cache215- [Artifacts](references/jobs/artifacts.md) — `expire_in`, `expose_as`, cross-pipeline sharing216- [Execution Flow](references/jobs/execution-flow.md) — `needs:`, `dependencies`, DAG patterns217- [Docker Builds](references/jobs/docker-builds.md) — DinD, Kaniko, Buildah, multi-stage218- [Git Strategies](references/jobs/git-strategies.md) — `GIT_STRATEGY`, `GIT_DEPTH`, submodules219- [Retry & Resilience](references/jobs/retry-resilience.md) — `retry:when`, `allow_failure`, timeout220221---222223## Runner Infrastructure224225Runners execute jobs. Executor choice determines security model, performance, and isolation.226227| Executor | Isolation | Best For | Autoscalable |228|----------|-----------|----------|--------------|229| Docker | Container | Most CI jobs | Yes (docker-autoscaler) |230| Kubernetes | Pod | Cloud-native, multi-container | Yes (native) |231| Shell | None | Simple scripts, host access | No |232| Docker Autoscaler | VM + Container | Cost-optimized cloud fleets | Yes |233| Instance | VM | Full isolation | Yes (fleeting) |234| VirtualBox | VM | Legacy, local testing | Yes (legacy) |235236**Key gotcha:** Docker-in-Docker (`dind`) requires `privileged: true` — significant security risk. Prefer Kaniko for container builds when possible.237238**References:**239- [Runner Architecture](references/runner/architecture.md) — manager model, executor types, compatibility240- [Executors](references/runner/executors.md) — Docker, K8s, shell config and comparison241- [Autoscaling](references/runner/autoscaling.md) — docker-autoscaler, fleeting, scaling policies242- [Runner Security](references/runner/security.md) — tokens, `allowed_images`, hardening243- [Performance](references/runner/performance.md) — `concurrent`, `check_interval`, tuning244- [Fleet Management](references/runner/fleet-management.md) — config.toml, Prometheus metrics245246---247248## CI/CD Components249250Components are reusable pipeline building blocks published to the CI/CD Catalog (GitLab 17.0+).251252```yaml253include:254 - component: $CI_SERVER_FQDN/my-org/my-component@1.2.0255 inputs:256 stage: test257 scan_level: full258```259260**Key gotcha:** Always pin component versions (`@1.2.0` or `@1` for major). Unpinned components are a supply-chain risk.261262**References:**263- [Component Authoring](references/components/authoring.md) — project structure, `spec:inputs`, Catalog264- [Catalog](references/components/catalog.md) — discovery, version pinning, evaluation265- [Inputs](references/components/inputs.md) — types, validation, defaults266- [Testing](references/components/testing.md) — self-referencing, integration tests267- [Security](references/components/security.md) — pinning audit, `include:integrity`268269---270271## Semantic Release272273Automated versioning with `@semantic-release/gitlab` and the `to-be-continuous` component.274275**Token setup:** Requires `GITLAB_TOKEN` (project access token with `api` scope) or `GL_TOKEN`. Must be masked and protected.276277**Key gotcha:** Set `GIT_DEPTH: 0` in the release job — shallow clones break commit analysis.278279**References:**280- [GitLab Integration](references/semantic-release/gitlab-integration.md) — plugin lifecycle, TBC, tokens281- [Configuration](references/semantic-release/configuration.md) — `.releaserc`, presets, hooks, GPG282- [Testing](references/semantic-release/testing.md) — dry-run, verification283284---285286## Deployment & Environments287288| Strategy | Pattern | Risk | Rollback |289|----------|---------|------|----------|290| Rolling | Replace instances incrementally | Medium | Redeploy previous version |291| Blue-Green | Switch traffic between environments | Low | Switch back |292| Canary | Route % of traffic to new version | Low | Reduce to 0% |293| Feature Flags | Toggle features in-app | Lowest | Disable flag |294295**Key gotcha:** Always set `auto_stop_in` on dynamic environments. Without it, review apps accumulate and leak resources.296297**References:**298- [Deployment Strategies](references/deployment/strategies.md) — blue-green, canary, rolling, feature flags299- [Dynamic Environments](references/deployment/environments.md) — review apps, auto_stop, cleanup300- [Infrastructure as Code](references/deployment/infrastructure-as-code.md) — Terraform/OpenTofu, state301- [Release Automation](references/deployment/release-automation.md) — changelog, orchestration302303---304305## Security306307| Feature | Keywords/Config | GitLab Tier |308|---------|----------------|-------------|309| Secret variables | `Settings > CI/CD > Variables` (masked + protected) | Free |310| Vault integration | `secrets:vault:` | Premium |311| OIDC/JWT auth | `id_tokens:` | Free (15.7+) |312| SAST | `include: SAST.gitlab-ci.yml` | Ultimate |313| Dependency scanning | `include: Dependency-Scanning.gitlab-ci.yml` | Ultimate |314| Container scanning | `include: Container-Scanning.gitlab-ci.yml` | Ultimate |315| Compliance frameworks | Project settings | Ultimate |316317**Key gotcha:** `CI_JOB_TOKEN` default scope allows access to all reachable projects. Restrict it via `Settings > CI/CD > Token Access`.318319**References:**320- [Secrets Management](references/security/secrets-management.md) — Vault, GCP, Azure, AWS, OIDC321- [Security Scanning](references/security/scanning.md) — SAST, DAST, container, dependency322- [Compliance](references/security/compliance.md) — frameworks, audit trails, governance323- [Pipeline Security](references/pipelines/security.md) — CI_JOB_TOKEN scoping, protected runners, fork safety324325---326327## Troubleshooting328329**Debugging decision tree:**3303311. **YAML syntax error?** → Use Pipeline Editor or CI Lint API3322. **Job not starting?** → Check `rules:` evaluation — View "merged YAML" in Pipeline Editor3333. **Variable not expanding?** → Check [scopes](references/variables/scopes.md) and [precedence](references/variables/precedence.md)3344. **Cache miss?** → Verify `cache:key` matches — check runner cache backend3355. **Artifact not found?** → Check `expire_in`, `dependencies:`, and `needs:artifacts:`3366. **Runner issues?** → Check tags, runner availability, executor config3377. **Need verbose output?** → Set `CI_DEBUG_TRACE=true` (⚠️ exposes secrets)338339**References:**340- [Troubleshooting Guide](references/troubleshooting.md) — editor, lint, debug trace, common errors341- [FAQ & Gotchas](references/faq.md) — top 25+ categorized gotchas with fixes342343---344345## Output Formats346347When producing specific types of analysis, use the corresponding output format spec:348349| Task | Output Style |350|------|-------------|351| Analyzing MegaLinter results | [megalinter-analysis](output-styles/megalinter-analysis.md) |352| Debugging pipeline failures | [troubleshooting-report](output-styles/troubleshooting-report.md) |353| Reviewing test results | [ci-tester-report](output-styles/ci-tester-report.md) |354| Reviewing pipeline architecture | [ci-architecture-review](output-styles/ci-architecture-review.md) |355356---357358## Version Compatibility359360Key feature introductions across GitLab versions:361362| Version | Feature | Impact |363|---------|---------|--------|364| 12.5 | `workflow:rules` | Pipeline-level conditional creation |365| 13.0 | `!reference` tag | Cross-file YAML references |366| 15.3 | `rules:changes:compare_to` | Baseline comparison for `rules:changes` (GA 16.0) |367| 13.9 | `needs:` cross-stage | DAG dependencies across stages |368| 14.2 | `include:rules` | Conditional file includes |369| 15.0 | `include:integrity` | SHA-pinned includes for supply chain security |370| 15.1 | `docker-autoscaler` executor | Modern runner autoscaling (replaces docker+machine) |371| 15.7 | `id_tokens:` | OIDC/JWT for external auth (Vault, cloud providers) |372| 16.0 | `CI/CD Components` beta | Reusable pipeline building blocks |373| 16.3 | `workflow:name` | Dynamic pipeline naming |374| 16.6 | `needs:parallel:matrix` | Fan-in from matrix jobs |375| 17.0 | CI/CD Catalog GA | Component discovery and versioning |376| 17.2 | `GIT_CLONE_EXTRA_FLAGS` | Custom git clone flags + native clone FF |377| 17.4 | `include:inputs` | Pass inputs to any included file |378| 18.0 | `run:` keyword | CI Steps (experimental) — replaces `script:` model |379380---381382## Related Resources383384- [GitLab CI/CD Documentation](https://docs.gitlab.com/ci/)385- [.gitlab-ci.yml Reference](https://docs.gitlab.com/ci/yaml/)386- [Predefined Variables](https://docs.gitlab.com/ci/variables/predefined_variables/)387- [CI/CD Component Catalog](https://gitlab.com/explore/catalog)388- [GitLab Runner Documentation](https://docs.gitlab.com/runner/)389390---391392## Workspace Examples393394Annotated analyses of real pipelines from this workspace:395396- [MAP Terragrunt Pipeline](examples/map-pipeline.md) — component includes, MegaLinter, release automation397- [Component Include Patterns](examples/component-patterns.md) — template structure, `spec:inputs` usage