DevOps / GitLab CI Basics Interview Questions
What is a merge request pipeline in GitLab CI and how does it differ from a branch pipeline?
GitLab supports two types of pipelines related to merge requests: branch pipelines (triggered by a push to a branch) and merge request pipelines (triggered specifically by merge request events). Understanding the difference is essential for designing efficient review workflows.
| Aspect | Branch Pipeline | Merge Request Pipeline |
|---|---|---|
| Trigger | Push to a branch | MR created, updated, or rebased |
| Source variable | push | merge_request_event |
| Runs on | The feature branch's HEAD | Merge result (branch + target merged) |
| MR status checks | Not shown in MR (unless configured) | Shown in MR as status checks |
| MR variables | $CI_MERGE_REQUEST_* not set | $CI_MERGE_REQUEST_* fully populated |
| Merged result | Tests the branch as-is | Tests what the code will look like after merge |
# Jobs that run only in MR pipelines: code-review: script: - run-code-quality.sh rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Useful MR-specific variables: check-mr: script: - echo "MR ID: $CI_MERGE_REQUEST_ID" - echo "Target branch: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME" - echo "Source branch: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" - echo "MR title: $CI_MERGE_REQUEST_TITLE" rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Merged results pipeline (tests the post-merge state): # Enable in Settings > Merge requests > Merged results pipelines # Runs on the merge commit that would result from accepting the MR
Merged results pipelines (enabled in project settings) run the CI on the simulated merge result - catching conflicts between the MR branch and the target branch that would only appear after merging. This is safer than testing just the source branch.
More Related questions...