I have been trying to set the environment variables GIT_AUTHOR_EMAIL
and GIT_COMMITTER_EMAIL
so that the GIT plugin for Jenkins claims to be setting(https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin).
I see that the rest of the environment variables viz. GIT_URL
, GIT_BRANCH
, GIT_COMMIT
, GIT_PREVIOUS_COMMIT
are set accurately for each of the jenkins jobs.
I am testing this by printing out all the environment variables in a jenkins jobs shell script build step by using printenv
.
Can somebody please let me know if I am missing something here ? Here are few of the possible reasons that I could think of..
Please help me in this regard.
Thanks!
p.s. I also saw a similar question is left unanswered (Github-plugin for Jenkins get committer and author name)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With