A predefined variable for branch name
Problem
We have the predefined variable CI_COMMIT_REF_NAME
for getting a branch name in a job. This variable works in most of the cases except pipelines for merge requests. In the nature of merge request pipelines, the value will be either refs/merge-requests/:iid/head
or refs/merge-requests/:iid/merge
. This will misbehave if you use the variable for Docker image tag or dynamic environment name of the review app.
With the Pipelines for merge requests, you can use an additional predefined variable CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
, but remember this value won't be exposed in a normal branch pipeline. If a pipeline runs on master, this value will be nil, thus things might not work as expected.
Now, let's say you want to get a branch name in any situation, but you cannot do in the current implementation.
Proposal
Fix CI_COMMIT_REF_NAME
to return generic branch name always. There will be no use case in returning merge request refs.