Skip to content

Add CI_COMMIT_FORCE_PUSH variable

Tyler Kellen requested to merge scaleoutllc/gitlab:detect-force-push into master

What does this MR do and why?

This (untested) change exposes a variable to CI pipelines that allow conditional branching when a force push occurs. The current version of gitlab incorrectly determines the list of files changed when a force push occurs. It would be possible to work around this incorrect handling by giving pipeline authors a variable for branching when a force push has occurred. This MR implements that variable.

How to set up and validate locally

Configure a .gitlab-ci.yml file with the following:

test:
  stage: test
  script:  
  - echo $CI_COMMIT_FORCE_PUSH

Run the following:

git init
touch foo
git add .
git commit -m "foo"
touch bar
git commit -m "bar"
git push origin main
git reset --hard HEAD~1
touch baz
git add .
git commit -m "baz"
git push origin main --force

Observe that the final push triggers a pipeline wherein CI_COMMIT_FORCE_PUSH is set to "true".

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marcel Amirault

Merge request reports