Command Palette

Search for a command to run...

GitLab CI/CD Setup Guide

Comprehensive guide for setting up and configuring GitLab CI/CD pipelines in your projects.

This guide provides detailed instructions for setting up GitLab CI/CD in your projects and creating efficient pipelines.

Requirements

  • GitLab account (Cloud or Self-hosted)
  • Repository with code to build/test/deploy
  • .gitlab-ci.yml file in repository root
  • GitLab Runner (Cloud or Self-hosted)

Basic Setup

Pipeline Configuration

# .gitlab-ci.yml
stages:
  - build
  - test
  - deploy
 
build:
  stage: build
  image: node:20
  script:
    - npm ci
    - npm run build
 
test:
  stage: test
  image: node:20
  script:
    - npm ci
    - npm test

Runner Setup

GitLab.com Shared Runners

Enable in Project Settings:

  1. Settings → CI/CD → Runners
  2. Enable shared runners

Usage Limits

# Free tier
- 400 CI/CD minutes/month
# Premium
- 10,000 CI/CD minutes/month
# Ultimate
- 50,000 CI/CD minutes/month

Common Pipeline Examples

CI/CD Variables

Cache and Artifacts

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/
    - .npm/
 
artifacts:
  paths:
    - dist/
  reports:
    coverage: coverage/lcov.info
    junit: junit.xml

Troubleshooting

Best Practices

  1. Pipeline Optimization

    • Use parallel jobs when possible
    • Implement caching strategy
    • Use dependencies wisely
    • Keep build times under 10 minutes
  2. Security

    • Use masked variables for secrets
    • Implement review apps
    • Scan for vulnerabilities
    • Use protected branches
  3. Maintenance

    • Regular runner updates
    • Clean old artifacts
    • Monitor pipeline metrics
    • Document CI/CD configurations