CI jobs need a "previous HEAD" variable
Problem
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.
History
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.
Example
If we take a look at the runner output, we can see that whatever kicks off the runner job seems to know what the previous REV is (in this example 94a71e3
):
Running with gitlab-ci-multi-runner 9.0.0 (08a9e6f)
on runner01 (54758559)
Using Shell executor...
Running on runner01...
Fetching changes...
HEAD is now at 94a71e3 Add line 6 to file.txt
From https://gitlab.mydomain.com/software/test
94a71e3..a4ca70d master -> origin/master
Checking out a4ca70d0 as master...
Skipping Git submodules setup
$ /home/gitlab-runner/bin/script.sh
Job succeeded