Use $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME when $CI_COMMIT_BRANCH is not set.
$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
$CI_COMMIT_BRANCH