Fix missing gitaly_context forward in BranchPushService
What does this MR do and why?
In order to prevent "CI loops" with the job token push feature, we set a
glBuildId
in the Gitaly context whenever a push originates from a CI
job, and forbid pipeline creation when this key is present. This was
already working for branches and tags, but we missed forwarding this
variable for merge request pipelines.
References
See !197418 (comment 2745993919)
Screenshots or screen recordings
Before | After |
---|---|
![]() |
N/A -- it just stops adding to the list |
How to set up and validate locally
In your GDK, create a project with the following .gitlab-ci.yml
:
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH
when: never
placeholder:
rules:
- if: $CI_COMMIT_BRANCH
script: echo "placeholder"
when: manual
allow_failure: true
push_to_mr:
rules:
- if: $CI_MERGE_REQUEST_IID
variables:
GIT_DEPTH: 0 # Disable shallow clone
script:
- apk add git
- git config http.sslVerify false # we're in GDK with a self-signed certificate or no TLS at all
- git config user.email "$GITLAB_USER_EMAIL"
- git config user.name "$GITLAB_USER_NAME"
# Fetch and checkout the MR source branch
- git fetch origin "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
- git checkout -B "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" "origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
# Make changes
- echo "$CI_PIPELINE_ID" >> PIPELINE_IDS
- git add PIPELINE_IDS
- git commit -m "Append $CI_PIPELINE_ID to PIPELINE_IDS"
# Push changes
- git push origin "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
Then create a merge request.
- Without these changes: Each commit results in a a new pipeline, indefinitely
- With these changes: The generated commit does not result in a pipeline being created
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.