CI/CD Pipelines - gitlab-org/gitlab-ce

CI/CD Pipelines with GitLab

GitLab’s continuous integration and continuous delivery/deployment (CI/CD) features automate builds, testing, and deployments for your project. This document explains the key concepts and provides examples for each option, using the official GitLab documentation.

The Big Picture

GitLab CI/CD is a system that builds, tests, and deploys your project based on a configuration file (.gitlab-ci.yml) in your repository. It uses a variety of technologies and programming languages, including Git, Ruby on Rails, Node.js, Tailwind CSS, Webpack, Babel, Sass, PostgreSQL, Redis, GraphQL, and more.

Design Philosophy

GitLab’s CI/CD system is designed to be a single application for the entire DevSecOps lifecycle, fulfilling all the fundamentals for CI/CD in one environment. This means you can build, test, deploy, and monitor your code from a single application, without relying on integrations with other tools.

Prerequisites

To get started with GitLab CI/CD, you need:

  1. Application code hosted in a Git repository.
  2. A file called .gitlab-ci.yml in the root of your repository, which contains the CI/CD configuration.

The .gitlab-ci.yml File

The .gitlab-ci.yml file is the configuration file for GitLab CI/CD. It contains jobs, stages, and scripts that define what, when, and how to build, test, and deploy your project. Here’s an example:

stages:
- build
- test

build_job:
stage: build
script: echo "Building the app"

test_job:
stage: test
script: echo "Testing the app"

This example defines two stages (build and test) and two jobs (build_job and test_job) that run in those stages.

Pipeline Architecture

GitLab CI/CD pipelines can be structured in different ways, depending on the complexity and needs of your project. The main methods are:

  1. Basic pipelines: Good for straightforward projects where all the configuration is in one place.
  2. Directed Acyclic Graph (DAG) pipelines: Good for large, complex projects that need efficient execution.
  3. Parent-child pipelines: Good for monorepos and projects with lots of independently defined components.
  4. Multi-project pipelines: Good for larger products that require cross-project interdependencies.

CI/CD Pipelines

CI/CD pipelines are the top-level component of continuous integration, delivery, and deployment in GitLab. They comprise jobs and stages that define what to do and when to run the jobs. Jobs are executed by runners, and multiple jobs in the same stage are executed in parallel if there are enough concurrent runners.

Version Control with GitLab

GitLab includes built-in CI/CD features that apply continuous integration, delivery, and deployment methods to software without requiring third-party applications or integrations. The built-in CI/CD features run automated scripts to preview changes with Review Apps, build and test applications, deploy apps to different environments, schedule pipelines, install runners, and check for vulnerabilities with security test reports.

Summary

GitLab’s CI/CD system is a powerful and flexible tool for automating builds, testing, and deployments. By using a .gitlab-ci.yml file in your repository, you can define jobs, stages, and scripts that build, test, and deploy your project based on your specific needs and requirements. With various pipeline architectures, you can structure your CI/CD system to fit the complexity and interdependencies of your project.

Sources:

  1. https://docs.gitlab.com/ee/ci/quick_start:
  2. https://docs.gitlab.com/ee/ci/yaml/gitlab_ci_yaml.html
  3. https://docs.gitlab.com/ee/ci/pipelines/pipeline_architectures.html
  4. https://about.gitlab.com/topics/ci-cd
  5. https://docs.gitlab.com/ee/tutorials/build_application.html
  6. https://docs.gitlab.com/ee/ci/examples
  7. https://about.gitlab.com/topics/ci-cd/cicd-pipeline
  8. https://docs.gitlab.com/ee/ci/pipelines
  9. https://about.gitlab.com/topics/version-control/how-implement-version-control
  10. https://edu.chainguard.dev/chainguard/administration/iam-groups/overview-of-enforce-iam-model
  11. https://docs.gitlab.com/ee/ci/quick_start/tutorial.html
  12. https://about.gitlab.com/topics/ci-cd/continuous-integration-continuous-delivery-work-together
  13. https://docs.gitlab.com/ee/ci/lint.html