Get the name of the source branch after an MR is merged in GitlabCI

Viewed 24

I have a Pipeline job that needs to run only after an MR has been merged to a certain branch (let’s assume it’s master).

This job is supposed to make an API call to send the name of the merged source branch.

The problem I’m encountering is that CI_MERGE_REQUEST_SOURCE_BRANCH_NAME will not be available on the Pipeline that runs right after the merge (since it’s not a merge request pipeline).

Is there a way (env var) to tell what was the branch that was just merged into master?

Many thanks in advance y’all!

1 Answers

Better you work with hashes not with the names.

Anyway I see two options:

  1. In the pipeline for the merge request save the hash/name in an artifact. The subsequent pipeline can access this artifact an read the hash/name.

  2. Run a independent pipeline and read the hash/name of the previous pipeline. To do this more secure you can add tags and read the previous pipeline only if it has the correct tag.

Related