How to get logged in username of Jenkins in parameter's Groovy script?

10 views
Skip to first unread message

Gajanan Mahajan

unread,
Jun 11, 2020, 12:19:51 AM6/11/20
to Jenkins Users
In Jenkins parameter, I'm writing Groovy script and in that script I need to pass Jenkins logged in username NOT user. User and username, could be different

Ex - User, that is displayed left to 'log out', could be - Bob Gill and username, used to login - could be - bob

User can be retrieved using `User.current()`. Please tell me how to get username.

**NOTE** I don't need username in pipeline code. I need it in Groovy script of parameter.

Giles

unread,
Jun 11, 2020, 1:07:25 PM6/11/20
to Jenkins Users
I use scripted pipeline.  The method I use:

def String JenkinsUserID;
wrap([$class: 'BuildUser']) {
    JenkinsUserID = env.BUILD_USER_ID;
}
println("DEBUG: found user '${JenkinsUserID}'.");

I'm embarrassed to admit that solution is more Internet-copy-paste than full comprehension (I don't understand the "wrap()" part, but it's needed), but it does do what I think you want.
Reply all
Reply to author
Forward
0 new messages