This looks exactly like [gitlab-org/gitlab
issue 17822][1] which requested, 4 years ago (Apr. 2017) a CI_PREV_COMMIT_SHA
In our GitLab setup we have CI jobs configured for only: master
(although
this issue is relevant outside that scope).
The problem we have is that we want some jobs to know what the "previous HEAD" was prior to the current job.
This would be relatively easy to get with a git log for MRs because the previous HEAD would simply be HEAD^
.
However, we also have privileged Master users who periodically push a series of commits to master all at once. In this scenario there is no way to figure out what HEAD
was prior to the push.
For this reason I was hoping we could get a variable like CI_PREV_COMMIT_SHA
or something similar which would provide this bit of information to the runner.
Prior to using GitLab, we were running automation with a post-receive hook in the bare repo, and this hook script is provided with both a previous and
current REV.
Now with GitLab CI runners, we have no way to replicate our script behavior
without knowing what the previous REV was.
That has not been implemented yet though: you might need (as a crude workaround) to store that information in a file, with a shared folder accessible from your build environment: you might then be able to read that file on the next occurrence of your job.
[1]: https://gitlab.com/gitlab-org/gitlab/-/issues/17822