Agents gitlab-cicd

Expert-level guidance for GitLab CI/CD pipeline configuration, development, optimization, debugging, and best practices.

install
source · Clone the upstream repo
git clone https://github.com/aRustyDev/agents
Claude Code · Install into ~/.claude/skills/
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"
manifest: content/skills/gitlab-cicd/SKILL.md
source content

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

KeywordPurposeDetail
script
Commands to execute in a jobRequired for every job unless
trigger
is used
rules
Conditional job inclusionReplaces deprecated
only/except
. See rules-patterns
needs
DAG dependency declarationJobs run as soon as dependencies finish, ignoring stage order
variables
Define CI/CD variablesScoped to job, pipeline, or global. See variable scopes
include
Import external YAMLTypes:
local
,
project
,
remote
,
template
,
component
extends
Inherit from hidden jobsUp to 11 levels deep; merged with job config
cache
Persist files between jobsUse
cache:key:files
for content-addressable caching
artifacts
Pass files between stages
expire_in
,
expose_as
, access control. See artifacts
image
Docker image for jobSet globally via
default:image
or per-job
services
Sidecar containersCommon:
docker:dind
, database services for testing
stages
Ordered execution groupsJobs in same stage run in parallel by default
workflow
Pipeline-level rulesControls whether pipeline is created. See workflow-rules
trigger
Start downstream pipelineParent-child (same project) or multi-project
environment
Deployment targetTiers,
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 controlEnsures only one job per group runs at a time
interruptible
Allow auto-cancelSet
true
on non-deployment jobs for pipeline efficiency

Quick Reference — Top 10 Predefined Variables

VariableValueAvailable
CI_COMMIT_REF_NAME
Branch or tag nameAlways
CI_COMMIT_SHA
Full commit SHAAlways
CI_PIPELINE_SOURCE
Trigger type (
push
,
merge_request_event
,
schedule
,
api
,
trigger
)
Always
CI_PROJECT_DIR
Workspace directory pathJob only
CI_JOB_TOKEN
Auto-generated token for API callsJob only
CI_REGISTRY_IMAGE
Container registry pathAlways
CI_MERGE_REQUEST_IID
MR internal IDMR pipelines only
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
MR source branchMR pipelines only
CI_ENVIRONMENT_NAME
Current environment nameDeployment 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 TypeTriggerKey Variable
Branch pipelinePush to branch
CI_COMMIT_BRANCH
Tag pipelinePush tag
CI_COMMIT_TAG
MR pipelineMR created/updated
CI_MERGE_REQUEST_IID
Merged resultsMR with merged results enabled
CI_MERGE_REQUEST_EVENT_TYPE=merged_result
Merge trainMR added to merge train
CI_MERGE_REQUEST_EVENT_TYPE=merge_train
ScheduledCron 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:


YAML Authoring

Pipeline YAML supports composition patterns for DRY, maintainable configurations.

PatternMechanismScope
extends
Job inheritance (11-level deep merge)Same file or included files
YAML anchors (
&
/
*
)
Same-file referenceSingle file only
!reference
Cross-file array extractionIncluded files (GitLab 13.0+)
include
External YAML importlocal, project, remote, template, component

Key gotcha: YAML anchors do NOT work across

include
boundaries — use
extends
or
!reference
instead.

References:


Variables

Variables follow an 11-level precedence hierarchy — knowing the order prevents hours of debugging.

Precedence (highest → lowest):

  1. Pipeline execution policy variables
  2. Scan execution policy variables
  3. Pipeline variables (trigger, scheduled, manual, API)
  4. Project variables (UI/API)
  5. Group variables (inherited, closest subgroup wins)
  6. Instance variables
  7. dotenv
    report variables
  8. Job-level YAML
    variables:
  9. Default (global) YAML
    variables:
  10. Deployment variables
  11. 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:


Jobs & Execution

FeatureKeywordKey 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:


Runner Infrastructure

Runners execute jobs. Executor choice determines security model, performance, and isolation.

ExecutorIsolationBest ForAutoscalable
DockerContainerMost CI jobsYes (docker-autoscaler)
KubernetesPodCloud-native, multi-containerYes (native)
ShellNoneSimple scripts, host accessNo
Docker AutoscalerVM + ContainerCost-optimized cloud fleetsYes
InstanceVMFull isolationYes (fleeting)
VirtualBoxVMLegacy, local testingYes (legacy)

Key gotcha: Docker-in-Docker (

dind
) requires
privileged: true
— significant security risk. Prefer Kaniko for container builds when possible.

References:


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:


Deployment & Environments

StrategyPatternRiskRollback
RollingReplace instances incrementallyMediumRedeploy previous version
Blue-GreenSwitch traffic between environmentsLowSwitch back
CanaryRoute % of traffic to new versionLowReduce to 0%
Feature FlagsToggle features in-appLowestDisable flag

Key gotcha: Always set

auto_stop_in
on dynamic environments. Without it, review apps accumulate and leak resources.

References:


Security

FeatureKeywords/ConfigGitLab 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 frameworksProject settingsUltimate

Key gotcha:

CI_JOB_TOKEN
default scope allows access to all reachable projects. Restrict it via
Settings > CI/CD > Token Access
.

References:


Troubleshooting

Debugging decision tree:

  1. YAML syntax error? → Use Pipeline Editor or CI Lint API
  2. Job not starting? → Check
    rules:
    evaluation — View "merged YAML" in Pipeline Editor
  3. Variable not expanding? → Check scopes and precedence
  4. Cache miss? → Verify
    cache:key
    matches — check runner cache backend
  5. Artifact not found? → Check
    expire_in
    ,
    dependencies:
    , and
    needs:artifacts:
  6. Runner issues? → Check tags, runner availability, executor config
  7. Need verbose output? → Set
    CI_DEBUG_TRACE=true
    (⚠️ exposes secrets)

References:


Output Formats

When producing specific types of analysis, use the corresponding output format spec:

TaskOutput Style
Analyzing MegaLinter resultsmegalinter-analysis
Debugging pipeline failurestroubleshooting-report
Reviewing test resultsci-tester-report
Reviewing pipeline architectureci-architecture-review

Version Compatibility

Key feature introductions across GitLab versions:

VersionFeatureImpact
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.0CI/CD Catalog GAComponent 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: