Get username logged in Jenkins from Jenkins Workflow (Pipeline) Plugin

Daniel Hernández picture Daniel Hernández · Mar 9, 2016 · Viewed 59.4k times · Source

I am using the Pipeline plugin in Jenkins by Clouldbees (the name was Workflow plugin before), I am trying to get the user name in the Groovy script but I am not able to achieve it.

stage 'checkout svn'

node('master') {
      // Get the user name logged in Jenkins
}

Answer

Jesse Glick picture Jesse Glick · Mar 9, 2016

Did you try installing the Build User Vars plugin? If so, you should be able to run

node {
  wrap([$class: 'BuildUser']) {
    def user = env.BUILD_USER_ID
  }
}

or similar.