CI_MERGE_REQUEST_DIFF_BASE_SHA not updating on branch change
Description: When changing the target branch for a merge request, the CI variable CI_MERGE_REQUEST_DIFF_BASE_SHA
is not being updated accordingly. This leads to discrepancies in the CI/CD pipeline, as the variable retains the value from the previous target branch. Consequently, the pipeline may incorrectly reference the old base SHA, potentially causing build failures or other unexpected behaviors.
Steps to Reproduce:
- Create a merge request with a specific source and target branch.
- Observe the value of
CI_MERGE_REQUEST_DIFF_BASE_SHA
in the CI/CD pipeline. - Change the target branch of the merge request.
- Re-run the CI/CD pipeline and check the value of
CI_MERGE_REQUEST_DIFF_BASE_SHA
.
Expected Behavior: CI_MERGE_REQUEST_DIFF_BASE_SHA
should be updated to reflect the new base SHA when the target branch of a merge request is changed.
Current Behavior: CI_MERGE_REQUEST_DIFF_BASE_SHA
retains the value from the previous target branch, causing inconsistencies in the CI/CD pipeline.
Environment:
- GitLab version: v16.8.1
- Runner version: v16.8.0
Importance: This issue is of high importance as it directly affects the accuracy and reliability of CI/CD pipelines. A fix is crucial to ensure that the CI variables accurately reflect the state of the merge request, preventing potential errors and misalignments in the pipeline process.
Workaround: Currently, there is no known workaround for this issue, making it imperative to address and resolve promptly. The only option developers have is to find the right sha with git-tooling.
Additional Information: Current workaround:
# first_commit=$CI_MERGE_REQUEST_DIFF_BASE_SHA ## determined manually due to bug in GitLab
if [[ -n $CI_MERGE_REQUEST_TARGET_BRANCH_NAME ]]; then
git fetch origin "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
first_commit=$(git merge-base "${current_commit}" "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}")
else
first_commit=$(git rev-parse HEAD^)
fi