Github-plugin for Jenkins get committer and author name

后端 未结 4 1573
失恋的感觉
失恋的感觉 2021-01-18 09:53

If I understand well, git plugin exposes committer and author names and emails to environmental variables GIT_AUTHOR_NAME, GIT_COMMITTER_NAME,

相关标签:
4条回答
  • 2021-01-18 10:38

    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()
    
    0 讨论(0)
  • 2021-01-18 10:40

    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.

    0 讨论(0)
  • 2021-01-18 10:47

    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.

    0 讨论(0)
  • 2021-01-18 10:48

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

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

    0 讨论(0)
提交回复
热议问题