I'm trying to run a GitLab pipeline job to move a Trello card to a different list, when the corresponding MR gets merged, but the job needs the MR's IID, to fetch its description, which contains the card ID.
On a merge request pipeline, I can get the MR's IID from the CI_MERGE_REQUEST_IID env var, but merge request pipelines run when MRs are created/updated, not when they get merged.
This is the way I found to make the job run only when a MR gets merged:
move-card-to-done:
stage: trello
image: $MY_TRELLO_INTEGRATION_IMAGE
tags:
- docker
only:
- main
when: on_success
script:
- moveCardToList $DONE_LIST_ID
The problem is that, since this is not a MR pipeline, the predefined variables I need are not available.
By printing all available env vars, the only reference to the MR I found was in CI_COMMIT_MESSAGE, but since this is customizable, there's no guarantee about its content.
This seems like a legitimate use-case. Isn't there a reliable way to do this?