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:
- mainFAQ
- 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
Validate a GitHub Actions Workflow
GitHub Actions workflows are YAML files where formatting errors prevent pipeline...
Validate a docker-compose.yml FileDocker Compose files are notoriously sensitive to indentation because YAML uses ...
Validate an Ansible PlaybookAnsible playbooks are YAML files that define automation tasks across servers. In...