Describe your question in as much detail as possible:
I have a workflow running on every push for my feature branch, where I use the CI variable CI_COMMIT_BEFORE_SHA inside of a git diff, with CI_COMMIT_SHA in order to get a list of files that have been changed.
However, as I often perform git squash and sometimes even drop some commits from my branch, I find myself often using force push with git push -f origin MY-BRANCH.
I have noticed that some of the deleted commits hash appears inside CI_COMMIT_BEFORE_SHA variable, and generate errors in the pipeline when used inside git diff.
As a relevant information, the exact command does work on my local computed because I have the history of squashed commits, but doesn’t seem to work on the gitlab-CI job. The actual hash for CI_COMMIT_BEFORE_SHA doesn’t even appears when I do git log on my branch (which make sense because it has been squashed) but indeed appears in git reflog (which is somehow a local tracking capability of git).
I think this is a bug, and this variable should not point to this hash. (I ended up using another solution)
-
What are you seeing, and how does that differ from what you expect to see?
When using any git related command on the commit SHA $CI_COMMIT_BEFORE_SHA I get an error basically saying that this hash does not correspond to any commit.
Wether on my local computer, I do see a relevant commit for this Hash, but only on my git reflog, not on gitlog (emphasizing here that this commit only exist locally) -
Consider including screenshots, error messages, and/or other helpful visuals
-
What version are you on? Are you using self-managed or GitLab.com?
- *GitLab : 14.7.2-ee enterprise version, self managed
-
Add the CI configuration from
.gitlab-ci.yml
and other configuration if relevant (e.g. docker-compose.yml)
build-job:
stage: build
script:
- export
- files=$(git diff --name-only --no-commit-id $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
- echo $files
- What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?
- I have checked the relevant documentation for variables available in CI, and there doesn’t seems to be anything suggesting that the behaviour is expected: Predefined variables reference | GitLab