$devtoolkit.sh/examples/yaml/gitlab-ci

Validate a GitLab CI Pipeline

GitLab CI pipelines are defined in .gitlab-ci.yml and must be valid YAML for the pipeline to start. This example shows a three-stage pipeline with lint, test, and deploy jobs. Common errors include incorrect stage references, missing colons after job names, and indentation problems in script lists. Validate before pushing to see errors without waiting for a pipeline run.

Example
stages:
  - lint
  - test
  - deploy

variables:
  NODE_ENV: test

lint:
  stage: lint
  image: node:20-alpine
  script:
    - npm ci
    - npm run lint

test:
  stage: test
  image: node:20-alpine
  script:
    - npm ci
    - npm test
  coverage: '/Liness*:s*(d+.?d*)%/'

deploy-production:
  stage: deploy
  script:
    - ./scripts/deploy.sh
  only:
    - main
[ open in YAML Validator → ]

FAQ

What is the only keyword in GitLab CI?
only restricts when a job runs. only: - main means the job only runs on the main branch. The newer rules keyword provides more flexible conditions.
How do I share variables between jobs?
Use the variables key at the top level for global variables. For artifacts (files) between jobs use the artifacts and dependencies keywords.
What is the difference between before_script and script?
before_script runs before the main script in every job and is useful for setup commands. script is the main list of commands for the job.

Related Examples

/examples/yaml/gitlab-civ1.0.0