Expose merge request pipeline variables
What does this MR do?
New predefined variables for MR pipelines
Variable name | Description | Sample value |
---|---|---|
CI_MERGE_REQUEST_ID |
The ID of the merge request | 34 |
CI_MERGE_REQUEST_IID |
The IID of the merge request (per project) | 1 |
CI_MERGE_REQUEST_REF_PATH |
The ref path to the merge request | refs/merge-requests/1/head |
CI_MERGE_REQUEST_PROJECT_ID |
The project id of the merge request | 1 |
CI_MERGE_REQUEST_PROJECT_PATH |
The project path of the merge request | namespace/awesome-project |
CI_MERGE_REQUEST_PROJECT_URL |
The project URL of the merge request | http://192.168.10.15:3000/namespace/awesome-project |
CI_MERGE_REQUEST_TARGET_BRANCH_NAME |
The target branch name of the merge request | master |
CI_MERGE_REQUEST_SOURCE_PROJECT_ID |
The source project id of the merge request | 10 |
CI_MERGE_REQUEST_SOURCE_PROJECT_PATH |
The source project path of the source project (with namespace) | namespace/awesome-forked-project |
CI_MERGE_REQUEST_SOURCE_PROJECT_URL |
The source project URL of the merge request | http://192.168.10.15:3000/namespace/awesome-forked-project |
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME |
The source branch name of the merge request | patch-1 |
export
Example of declare -x CI_MERGE_REQUEST_ID="36"
declare -x CI_MERGE_REQUEST_IID="3"
declare -x CI_MERGE_REQUEST_PROJECT_ID="51"
declare -x CI_MERGE_REQUEST_PROJECT_PATH="root/mr-variables"
declare -x CI_MERGE_REQUEST_PROJECT_URL="http://192.168.10.15:3000/root/mr-variables"
declare -x CI_MERGE_REQUEST_REF_PATH="refs/merge-requests/3/head"
declare -x CI_MERGE_REQUEST_SOURCE_BRANCH_NAME="patch-3"
declare -x CI_MERGE_REQUEST_SOURCE_PROJECT_ID="51"
declare -x CI_MERGE_REQUEST_SOURCE_PROJECT_PATH="root/mr-variables"
declare -x CI_MERGE_REQUEST_SOURCE_PROJECT_URL="http://192.168.10.15:3000/root/mr-variables"
declare -x CI_MERGE_REQUEST_TARGET_BRANCH_NAME="master"
Usage: Sample script to create a merge commit within the job
job:
script:
- git fetch "$CI_MERGE_REQUEST_PROJECT_URL" "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- git merge FETCH_HEAD
- # Test on the merge commit
only: [merge_requests]
Usage: Access API
#!/bin/bash
curl --header "Private-Token: yyM1RF_aWpf_RZNHAhMa" "http://192.168.10.15:3000/api/v4/projects/${CI_MERGE_REQUEST_PROJECT_ID}/pipelines"
curl --header "Private-Token: yyM1RF_aWpf_RZNHAhMa" "http://192.168.10.15:3000/api/v4/projects/${CI_MERGE_REQUEST_SOURCE_PROJECT_ID}/pipelines"
What are the relevant issue numbers?
Related: https://gitlab.com/gitlab-org/gitlab-ce/issues/15310
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary - [-] Documentation created/updated => https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23397
-
Tests added for this feature/bug -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides - [-] Link to e2e tests MR added if this MR has Requires e2e tests label. See the Test Planning Process.
Edited by Shinya Maeda