DevOps

GitLab CI/CD

GitLab CI/CD is the build and delivery system built into GitLab, configured with a .gitlab-ci.yml file.

What it is

GitLab CI/CD is part of the GitLab platform, which also includes the repository, code review, container registry and security. Built-in CI integration arrived in GitLab 8.0 in 2015.

A pipeline is described in .gitlab-ci.yml at the repo root: stages set the order, jobs within a stage run in parallel, and they are executed by runners you can install on your own servers. It has artifacts, cache, environments, merge request pipelines and Auto DevOps.

GitLab can be self-hosted (Community Edition under MIT) or used as GitLab.com. It is a popular choice for companies that want code and CI in their own infrastructure.

Use it when

  • Your code is in GitLab and you want CI without another service.
  • You need a self-hosted platform with repository, CI and registry in one place.
  • You need merge request pipelines and built-in security scanning.

Avoid it when

  • Your code is on GitHub: GitHub Actions is the more natural choice.
  • You need only the simplest builds and the whole GitLab platform is overkill.

Key concepts

Pipeline / stage / job
A pipeline is a set of stages, a stage is a group of parallel jobs, a job is one task.
Runner
The agent that runs jobs: shared by GitLab or your own.
Artifacts / cache
Artifacts pass results between stages, cache speeds up repeated builds.
Environments
Named deploy targets (staging, production) with deploy history.

Example

Two stages: tests in a Node container and an image build on the main branch.

Interview questions

  1. 1. What is a runner in GitLab?

    A process that takes jobs from GitLab and executes them, in a shell, Docker or Kubernetes. GitLab provides shared runners, and you can register your own on your servers.

  2. 2. How do you pass files between stages?

    Through artifacts: a job saves files and later stages receive them automatically. Cache is meant for dependencies across runs, not for passing results.

  3. 3. How does GitLab CI differ from Jenkins?

    GitLab CI is built into the platform and configured with YAML in the repo. Jenkins is a separate server with plugins and a Jenkinsfile, more flexible but needing more maintenance.

Interview questions from the bank

Comparisons with this technology

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).