Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github-plugin for Jenkins get committer and author name

If I understand well, git plugin exposes committer and author names and emails to environmental variables GIT_AUTHOR_NAME, GIT_COMMITTER_NAME, GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL based on the global configuration of git. Is there a way to get that info using Github-plugin? Does Github-plugin exposes payload info, getting from github-webhook, to environmental variables or to something else?

like image 503
czalidis Avatar asked Mar 07 '14 16:03

czalidis


3 Answers

In reality these variables are available just when you overwrite the Author Name and Author Email on the Advanced features of the SCM configuration.

"Additional Behaviours" -> "Custom user name/email address"

This is described on the source code: https://github.com/jenkinsci/git-plugin/tree/master/src/main/java/hudson/plugins/git


Solution: In order to retrieve the author name and email I suggest scripting this:

GIT_NAME=$(git --no-pager show -s --format='%an' $GIT_COMMIT)
GIT_EMAIL=$(git --no-pager show -s --format='%ae' $GIT_COMMIT)

Being $GIT_COMMIT the SHA1 commit id.

like image 163
Custodio Avatar answered Oct 23 '22 12:10

Custodio


You can use this workaround in your scripted pipeline file:

env.GIT_COMMITTER_EMAIL = sh(
   script: "git --no-pager show -s --format='%ae'",
   returnStdout: true
).trim()
like image 27
Juan Avatar answered Oct 23 '22 10:10

Juan


You can try for below command, it worked for me:

git log -n 1 --pretty=format:'%ae'

like image 2
OMKAR CHAVAN Avatar answered Oct 23 '22 10:10

OMKAR CHAVAN