Github-plugin for Jenkins get committer and author name

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:16:35

问题


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?


回答1:


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.




回答2:


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()



回答3:


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.




回答4:


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

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



来源:https://stackoverflow.com/questions/22256083/github-plugin-for-jenkins-get-committer-and-author-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!