I need to find the git username/email of a person who is pushing changes, consisting of different commits by different users, to a remote repository.
The push triggers a Post-Receive hook via gitblit which triggers a jenkins job, and is using a non user specific SSH authentication.
Jenkins does not provide an easy way to accomplish that. I had a similar problem and it took me some time to find a suitable solution.
I ended up using a combination of the Environmental Variables of Git Plugin and git log.
Git Plugin offers two environmental variables:
which you get every time your git Web Hook triggers the Jenkins job.
On the other hand,
git log
provides the means to get the author name and author email using theformat
command option.Therefore, combining those two options you can get the author name and email of each commit between your previous commit which triggered the Jenkins job : GIT_PREVIOUS_COMMIT and the current commit : GIT_COMMIT using the
git log
command below:in an Executed Shell in your Jenkins Job. Please make sure that you are in root of your git project.
I had to
.
myuser is now an enviroment variable, here as an example in an ant script :