Cannot pass variable to the jobs of pipeline when calling "Create MR Pipeline" API
Summary
I triggered a pipeline calling the create-a-new-pipeline API. The variables are passed.
curl --silent --request "POST" \
--header "PRIVATE-TOKEN: $GITLAB_PRIVATE_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"ref": "$CI_COMMIT_REF_NAME",
"variables": [ {"key": "KEY1", "value": "VAL1"} ]
}' https://gitlab.com/api/v4/projects/$MY_PROJECT_PATH_SLUG/pipeline
But now when I triggered a MR pipeline calling the create-mr-pipeline. The variables are not passed.
curl --silent --request "POST" \
--header "PRIVATE-TOKEN: $GITLAB_PRIVATE_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{ "variables": [ {"key": "KEY1", "value": "VAL1"} ]
}' https://gitlab.com/api/v4/projects/$MY_PROJECT_PATH_SLUG/merge_requests/$CI_MERGE_REQUEST_IID/pipelines
Steps to reproduce
- Create a project including a job that run on merge request only
test-mr:
image: alpine
script:
- echo "KEY1=$KEY1"
only:
- merge_requests
- Try to trigger this job using create-mr-pipeline API
curl --silent --request "POST" \
--header "PRIVATE-TOKEN: $GITLAB_PRIVATE_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{ "variables": [ {"key": "KEY1", "value": "VAL1"} ]
}' https://gitlab.com/api/v4/projects/$MY_PROJECT_PATH_SLUG/merge_requests/$CI_MERGE_REQUEST_IID/pipelines
You should see "KEY1=" as result instead of the expected "KEY1=VAL1".
Example Project
See the previous chapter (version - GitLab EE 12.4.1).
What is the current bug behavior?
Variables are not passed when triggering a MR pipeline using the create-mr-pipeline API
What is the expected correct behavior?
Variables are passed when triggering a MR pipeline using the create-mr-pipeline API
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Results of GitLab application Check
Possible fixes
Edited by Stanislas PEYSSARD