Skip to content
Latchkey

GitLab CI Keywords Cheat Sheet: Every .gitlab-ci.yml Keyword

A keyword-by-keyword reference for .gitlab-ci.yml job configuration.

The job, control-flow, and artifact keywords for GitLab pipelines.

Job keywords

KeywordPurpose
scriptShell commands to run
before_script / after_scriptSetup / teardown
stageWhich stage the job belongs to
imageDocker image
servicesLinked containers
tagsSelect runners by tag
variablesJob-level env vars

Control flow

KeywordPurpose
rulesConditional inclusion (replaces only/except)
needsDAG dependencies (out-of-stage)
whenon_success / on_failure / always / manual
allow_failureDo not fail pipeline
dependenciesLimit which artifacts to fetch
extendsInherit from a template job

Caching & artifacts

KeywordPurpose
cache:key / cache:pathsReusable cache between runs
cache:policypull / push / pull-push
artifacts:pathsFiles to pass downstream
artifacts:expire_inRetention window
artifacts:reportsjunit, coverage, dotenv

Example

.gitlab-ci.yml
deploy:
  stage: deploy
  extends: .base
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: manual
  needs: [build]
  script: ./deploy.sh ${CI_ENVIRONMENT_NAME}

Key takeaways

  • Prefer rules over the legacy only/except.
  • needs creates a DAG so jobs start before their stage.
  • cache:policy: pull on consumers avoids redundant uploads.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →