We need to generate commit history file automatically when user commits code into git repository.
It can be done using Jenkins, Gitlab Webhooks and Jenkins Git Changelog plugin. Also, it can be created using below git command.
$ git log --pretty=format:'At %ci, %cN committed %h : %s' --decorate --graph >log.log
But, is there anyway we can generate commit history file using Gitlab CI/CD operations. The file can be saved in git repositry or local storage.
Sample Commit History File
* At 2018-11-16 18:02:21, kRiZ committed 1714a95 : Commit 4
* At 2018-11-15 16:06:06, kRiZ committed bab5c0c : Commit 3
* At 2018-11-14 18:05:09, kRiZ committed b3c9d86 : Commit 2
* At 2018-11-14 06:47:34, kRiZ committed 8e6ee30 : Add README.md
I'm sure there are multiple ways of doing this in GitLab. Here's one:
.gitlab-ci.yaml
file at the root of your repository. You can do this locally or using GitLab's web UI.Paste this snippet into your .gitlab-ci.yaml
file:
changelog:
image: docker:git
script:
- git log --pretty=format:'At %ci, %cN committed %h - %s' --decorate --graph >log.log
artifacts:
paths: [log.log]
Either commit and push locally or commit on GitLab's Web UI. The changelog
job will be triggered.
log.log
file will be available as an artifact of the changelog
jobEssentially, with this snippet you are setting up GitLab's CI/CD system to:
git
preinstalledchangelog
job that will run your git commandlog.log
artifact that will be generated as part of the job and stored, so that you can download it afterwards.I'd also recommend checking out the GitLab CI/CD quickstart