EagleOne
EagleOne

Reputation: 571

Gitlab CI: get list of files changed since last run

I'm currently working on CI with Gitlab CI.

I am able to get a list of modified files between last two commmit using:

git log -m -1 --name-only --pretty="format:"  HEAD

But I would like to have the list of files changed since last Gitlab CI run, that may include more than one commit. Is there any way to get such list?

Upvotes: 1

Views: 2342

Answers (1)

VonC
VonC

Reputation: 1324576

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

Upvotes: 1

Related Questions