I’m trying to have access to these predefined variables for merge requests pipelines in GitLab, but apparently my pipeline is set up as basic pipelines, thus having access only to these variables. I basically need only the CI_MERGE_REQUEST_ID
var. What do I need to configure (in terms of .gitlab-ci.yml
, project, etc) in order to “convert” a basic pipeline into a merge request pipeline in GitLab?
1
CI_MERGE_REQUEST_ID
is available as a predefined CI when you create a Merge request. It are not available in Branch and Tags pipelines. On the other hand, for example CI_COMMIT_BRANCH
is not available as a predefined CI variable during a merge request.
For example in the following one, I am running a job only if a merge request has been created ($CI_PIPELINE_SOURCE == “merge_request_event”) and the target of the merge request is the main branch of repository:
build:
stage: build
script:
- echo "Test"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
when: always
- when: never