gitlabgitlab-ci

How to access $CI_MERGE_REQUEST_LABELS after a merge request is merged?


Our use case:

To trigger our deployment job, which is deploying code to our Elastic beanstalk ENVs multiple times after merging a merge request. This means after the MR is merged, we want to run the deployment job again and again to deploy code from master branch on different EB ENVs.

To get which EB ENV we need to deploy our code to, we are using CI_MERGE_REQUEST_LABELS but after a merge request is merged, it doesn't have any value attached to it which is acceptable according to the doc.

What can be a way around this -- to get the value of CI_MERGE_REQUEST_LABELS after a merge request is merged? We ideally want to run this deployment job multiple times to deploy code to more than 1 EB ENVs.

I tried storing the value of CI_MERGE_REQUEST_LABELS and passing it to the downstream deployment job but this won't work when the merge request is merged.

I also tried fetching the value of CI_MERGE_REQUEST_LABELS from the API but again in that case, CI_MERGE_REQUEST_IID will not be available after the MR is merged.

curl --silent --header "PRIVATE-TOKEN: GITLAB_API_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID" | jq -r '.labels | join(",")

Am I missing something? Can I use another method to achieve the use case?


Solution

  • I solved my use case without using $CI_MERGE_REQUEST_LABELS and instead I defined variables and ran my pipeline manually.

    Doc: https://docs.gitlab.com/ee/ci/pipelines/#configure-a-list-of-selectable-prefilled-variable-values