14

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..

  1. Bug with the plugin
  2. Issue with Jenkins setup/config
  3. Issue with GIT config in Github..

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)

Community
  • 1
  • 1
aram87
  • 141
  • 1
  • 4

2 Answers2

11

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.

Custodio
  • 8,594
  • 15
  • 80
  • 115
  • You say "scripting this", what do you mean? In what way? I'm trying to do this in a Jenkins Pipeline on windows and I'm not sure what you meant. – Hector S. Jul 30 '18 at 20:26
  • As far as I remember I added one step (execute sh or bash or cmd) to add this environment variables. Does it make sense? – Custodio Jul 31 '18 at 14:46
  • Yeah, that makes sense. I was able to do it in CMD/PS, but I need for the Slacksend plugin step and I still have not figured out how to make that work. Thanks! – Hector S. Jul 31 '18 at 15:03
0

GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL are not automatically setup from the plugin. These are variables that YOU can setup in the individual job or at system level.

To setup these variables on a specific job, do the following:

  1. In the Source Code Management select the "Git" radio button and fill in the "Repository URL" and credentials as you would normally do.
  2. Click on the "Advanced ..." button, which will display a few additional fields and pull down menus
  3. From the "Additional Behaviours" pull down menu, select the "Custom user name/email address", which will provide two input fields for these settings.

You can set these variables at system level by selecting "Manage Jenkins" >> "Configure System" and then entering values for the user.name and user.email in the "Git plugin" section of the configuration page.

rgulia
  • 523
  • 7
  • 11