I would like to add to Gitlab pipeline a stage which verifies that the person approving the MR is different from the person doing the creation/merge (for this to work, I checked the setting in Gitlab that says: "Pipelines must succeed").
stages:
- quality
...
check-approval:
stage: quality
only:
- merge_request
script:
- >
author=$(curl -s --location --request POST 'https://xxxxx.com/api/graphql' --header 'Content-Type: application/json' --header "JOB-TOKEN: $CI_JOB_TOKEN" --data-raw '{"query":"query{project(fullPath: \"yyyyy/yyyyy/yyyyy\") {mergeRequest(iid:\"'$CI_MERGE_REQUEST_IID'\"){approvedBy{nodes{name}}author{name}}}}"}' | jq '.data.project.mergeRequest.author.name')
- >
approvedBy=$(curl -s --location --request POST 'https://xxxxx.com/api/graphql' --header 'Content-Type: application/json' --header "JOB-TOKEN: $CI_JOB_TOKEN" --data-raw '{"query":"query{project(fullPath: \"yyyyy/yyyyy/yyyyy\") {mergeRequest(iid:\"'$CI_MERGE_REQUEST_IID'\"){approvedBy{nodes{name}}author{name}}}}"}' | jq '.data.project.mergeRequest.approvedBy.nodes[].name')
- if [[ "$author" == "$approvedBy" ]]; then exit 1; else echo "MR can be merged"; fi
However, because I add the item only: - merge_request, there are two pipelines running (branch + merge) in parallel.
My questions are:
- how can I make the branch pipeline also run in the merge pipeline?
- is there any way to only run the stage of the pipeline that gave an error?