snippetMinor
How to get logged in username of Jenkins in parameter's Groovy script?
Viewed 0 times
scriptjenkinsusernamegethowloggedparametergroovy
Problem
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
NOTE I don't need username in pipeline code. I need it in Groovy script of parameter.
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.
Solution
From the Java API documentation for
Returns the user name.
Gets the human readable name of this user.
It's not clear to me from your question what data you want (I think it's the user ID?), so I'm not sure which of these methods will get you that data (
hudson.model.User:String getDisplayName()Returns the user name.
String getFullName()Gets the human readable name of this user.
String getId()It's not clear to me from your question what data you want (I think it's the user ID?), so I'm not sure which of these methods will get you that data (
getId()?). But in any case, you would call the method like:User.current().getId()Code Snippets
User.current().getId()Context
StackExchange DevOps Q#11805, answer score: 5
Revisions (0)
No revisions yet.