Reputation: 3581
I have a job that gets built in two ways :
within my pipeline, I need to get the name/info of person who triggered the build either directly (manually) or indirectly(SCM commit). I have the following code:
node('slave'){
wrap([$class: 'BuildUser']) {
return BUILD_USER
}
}
This gets me the name using the https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin plugin.
This works on manual but always gives SCM trigger when through SCM trigger. How do I get the name/info of the person who committed for the trigger to happen via SCM ?
Upvotes: 3
Views: 2424
Reputation: 2976
ScmTrigger does not hold information about the user who committed to git. You can get the user who commited by using git command:
git log --format='%an <%ae>' GIT_COMMIT_ID
Another option is to use a git hook that will trigger the job instead of SCM polling. in that case you can pass the commiter from the hook to the job. (for example https://www.fourkitchens.com/blog/article/trigger-jenkins-builds-pushing-github)
Upvotes: 1