GitLab CI Generator

Generate production-ready `.gitlab-ci.yml` pipelines with stages, caches, and jobs.

GitLab CI Pipeline

Global Configuration

Pipeline Stages

Pipeline Jobs

.gitlab-ci.yml
1

How to Write a .gitlab-ci.yml File

What is GitLab CI?

GitLab CI/CD is a tool built into GitLab for software development through the continuous methodologies: Continuous Integration, Continuous Delivery, and Continuous Deployment.

Configurations are defined in a file named .gitlab-ci.yml, which sits at the root of your repository.

Key Concepts

#

Stages and Jobs

A pipeline is composed of independent jobs that run scripts, grouped into stages. Stages run sequentially, while jobs within the same stage run in parallel.

  • build: Compile code or build Docker images.
  • test: Run unit, integration, and security tests.
  • deploy: Push code to staging or production environments.
  • #

    Artifacts and Caching

  • Artifacts: Used to pass intermediate build results between stages (e.g., passing a compiled binary from the build stage to the deploy stage).
  • Cache: Used to speed up the execution of jobs by storing dependencies (e.g., node_modules) that can be reused in subsequent pipeline runs.
  • Best Practices for GitLab CI

  • Use Docker-in-Docker Carefully: When building images, DIND is useful but can be insecure if not configured with TLS.
  • Pin Image Tags: Never use latest for job images. Always pin to specific versions to avoid unexpected pipeline breakages.
  • Use Rules: The rules keyword replaces the older only/except syntax and provides powerful logic for deciding when a job should run.