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?

- 61
- 1
- 1
- 4
4 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.

- 8,594
- 15
- 80
- 115
-
2the solution works if you run it during the build context that has git available to it. you may not actually need to include the git commit either (I didn't). For the full solution if you're trying to get these values **into an email subject** (isn't that useful) - add these to a text properties file `echo "GIT_AUTHOR=${GIT_AUTHOR}" >> build_params.txt` and then use email-ext plugin and the format `${PROPFILE, file="build_params.txt", property="GIT_AUTHOR"}` – David Merritt Nov 03 '16 at 19:47
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()

- 118
- 1
- 6
You can try for below command, it worked for me:
git log -n 1 --pretty=format:'%ae'

- 101
- 1
- 5
You need check who is contributing this variables, github plugin only triggers git build that runs Git SCM (that is git-plugin). This variables probably injected by git-plugin.

- 771
- 1
- 6
- 7