I’m trying to use the predefined GitLab CI/CD variables CI_MERGE_REQUEST_LABELS
and CI_MERGE_REQUEST_DESCRIPTION
to control whether the pipeline should execute when merging a Merge Request (MR) into master
.
According to the GitLab 17.8 documentation (Predefined CI/CD variables), these variables should be available inside the pipeline. However, when running env
after the merge, they are not present in the environment.
I created an MR with:
NO_DEPLOY
THIS_IS_A_DESCRIPTION
Here’s a simple .gitlab-ci.yml
I used for debugging:
image: alpine:latest
stages:
- test
test-merge-request:
stage: test
script:
- $CI_MERGE_REQUEST_DESCRIPTION
- $CI_MERGE_REQUEST_LABELS
- env
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"'
Issue: After merging the MR into master, neither CI_MERGE_REQUEST_LABELS nor CI_MERGE_REQUEST_DESCRIPTION appear in the pipeline logs.
Questions:
Any insights or solutions would be appreciated.
The CI_MERGE_REQUEST_LABELS
and CI_MERGE_REQUEST_DESCRIPTION
variables are only available for merge request pipelines, i.e. $CI_PIPELINE_SOURCE == "merge_request_event"
, when the merge request is open (See Predefined variables for merge request pipelines).
In your debug example, you check that CI_PIPELINE_SOURCE
is push
, in which case the pipeline trigger will be the merge commit instead of a merge request event. Thus, the merge request related CI variables are not defined.