2
votes

I have a job that gets built in two ways :

  1. IF someone commits to the github repo , triggering the job.
  2. IF someone manually builds the job.

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 ?

1
Possible duplicate of how to get $CAUSE in workflowJazzschmidt

1 Answers

1
votes

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
  • %an is the author's name
  • %ae is the author's email

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)