GitLab CI/CD
Git-integrated CI/CD with powerful pipeline orchestration.
Quick Start
stages:
- test
- build
- deploy
test:
stage: test
image: node:20
script:
- npm ci
- npm test
build:
stage: build
script:
- npm run build
artifacts:
paths:
- dist/
When to Use
- GitLab-hosted repositories
- Auto DevOps deployments
- Multi-project pipelines
- Container registry integration
Step-by-Step
- Add
.gitlab-ci.ymlto repo root - Configure stages and jobs
- Set up GitLab Runner
- Push to trigger pipeline
Dependencies
# Local runner
gitlab-runner register
Examples
deploy:
stage: deploy
only:
- main
script:
- kubectl apply -f k8s/
environment: production
Resources
Troubleshooting
- Job stuck in pending — runner has no tag match. Add
tags: [docker]to the job or register the runner with matching tags. - Pipeline fails on
npm ci— cache is stale. Clear the cache from CI/CD → Pipelines → Run pipeline or bump the cachekey. - Deploy stage skipped —
only: [main]blocks feature branches; userules: [if: '$CI_COMMIT_BRANCH == "main"']for finer control. - Runner runs as
sh, notbash— setimageper job or use POSIX-compatible script lines (|| true, noset -o pipefail).
Validation
- Pipeline starts on commit
- All stages execute in order
- Deployments succeed