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

后端 未结 10 656
忘了有多久
忘了有多久 2020-12-25 12:36

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 ach

10条回答
  •  粉色の甜心
    2020-12-25 12:56

    Here's a slightly shorter version that doesn't require the use of environment variables:

    @NonCPS
    def getBuildUser() {
        return currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()
    }
    

    The use of rawBuild requires that it be in a @NonCPS block.

提交回复
热议问题