Prev Next

DevOps / Gitlab Interview questions

Explain the internal working of GitLab merge trains?

A merge train solves a specific problem: when several merge requests are approved around the same time and merged one after another, each one was only tested against the target branch as it existed before the others merged. Two individually-passing MRs can still break the target branch once combined.

flowchart LR A[MR-1 added to train] --> B[Merged into virtual target: main + MR-1] C[MR-2 added to train] --> D[Merged into virtual target: main + MR-1 + MR-2] B --> E{Pipeline passes?} D --> F{Pipeline passes?} E -->|Yes| G[MR-1 merged to real main] F -->|Yes| H[MR-2 merged to real main] E -->|No| I[MR-1 removed from train] F -->|No| J[MR-2 removed from train]

Instead of testing each MR against the current main in isolation, GitLab builds a temporary, cumulative "virtual" branch for each position in the train: the first MR is tested against main, the second is tested against main plus the first MR's changes, and so on down the queue. Only if that virtual pipeline passes does the MR actually get merged into the real target branch, in order.

If a pipeline for an MR in the middle of the train fails, that MR is dropped, and every MR behind it in the queue is automatically re-tested against the corrected sequence, rather than merging on top of a change that never actually landed. This keeps main guaranteed-green even under a high rate of concurrent merges, which plain sequential merging can't promise.

The core problem merge trains solve is:
When an MR in the middle of a merge train fails its pipeline:

More Related questions...

What is GitLab? What is Git? What is the difference between Git and GitLab? What is the difference between GitLab and GitHub? What are the main features of GitLab? What is a GitLab repository? What is a GitLab merge request? What are GitLab CI/CD pipelines? What is a.gitlab-ci.yml file? What is a GitLab Runner? What are stages and jobs in a GitLab pipeline? What is a GitLab Issue Board? What are GitLab Epics? What is the difference between a GitLab group and a GitLab project? What is GitLab Container Registry? What is GitLab Pages? What are protected branches in GitLab? What is GitLab Auto DevOps? What is forking in GitLab? What are labels in GitLab? What is the GitLab Wiki? What are the different GitLab subscription tiers? What is GitLab Flow? What is a GitLab milestone? What is a GitLab Snippet? Explain the execution flow of a GitLab CI/CD pipeline from commit to deployment? Why would a DevOps team choose GitLab over GitHub for a single-platform workflow? How does a GitLab merge request differ from a GitHub pull request? What is the difference between GitLab.com (SaaS) and GitLab self-managed? How do you write a multi-stage.gitlab-ci.yml pipeline? When should you use CI/CD variables versus environment-scoped variables in GitLab? How do you troubleshoot a GitLab Runner stuck in "pending"? What is the difference between shell, Docker, and Kubernetes GitLab Runner executors? How does GitLab enforce merge request approvals with Code Owners? Explain the internal working of GitLab merge trains? What is the difference between GitLab CI/CD and Jenkins? How do you implement GitOps with GitLab and Kubernetes agent? Why use GitLab Auto DevOps instead of hand-writing pipelines? What is the difference between "include" and "extends" in GitLab CI/CD YAML? How does GitLab cache artifacts between pipeline jobs? When would you choose GitLab Ultimate over GitLab Premium? How do you configure branch protection rules to enforce a merge-request-only workflow? What is the difference between GitLab CI/CD "rules" and the deprecated "only/except" keywords? Explain the lifecycle of a GitLab issue from creation to closure? How do you optimize GitLab CI/CD pipeline performance for a large monorepo? What is the difference between GitLab Container Registry and Docker Hub? How does GitLab's Auto DevOps decide which CI/CD template to apply to a project? Why should you use GitLab environments to track deployments? What is the difference between a group-level and project-level CI/CD variable in GitLab? How do you troubleshoot merge conflicts flagged in a GitLab merge request?
Show more question and Answers...


Comments & Discussions