jenkinsgroovyjenkins-pipelinecloudbees

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


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
}

Solution

  • 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.