I have requirement to get logged user id information into Jenkins plugins.
I have created HelloWorldclass which extend hudson.tasks.Builder class for creating plugin. From this class, I am trying to get logged user in perform method.
I have tried various option but could not get logged user, every options return SYSTEM as user id.
User.current() :- Return SYSTEM on Jenkins console but on jenkins script console gives me perfect result but same code does not have me logged user information.
Yet, while I'm hunting around, I can see that the user id is always displaying in the top right corner of the UI, taunting me since it is the information I want, but seemingly not available.
Can anybody help to solve this problem.
The first time you start Jenkins, the configuration is created along with the initial default administrator account. If for some reason you have skipped the user-creation step in the setup wizard, you can use the default admin username and password to access the Jenkins UI.
I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER .
The @NonCPS annotation is useful when you have methods which use objects which aren't serializable. Normally, all objects that you create in your pipeline script must be serializable (the reason for this is that Jenkins must be able to serialize the state of the script so that it can be paused and stored on disk).
User.current()
gets you an User
object representing the current user on which, if printed in Jenkins' Script Console, toString()
is invoked. Which in turn most probably invokes getFullName()
(or getDisplayName()
– didn't check that in code and it's neither obvious from the API, it lacks proper description, nor the Manage User UI, since there is just one field: Full name).
User.current().getId()
gets you the user's ID.
See hudson.model.User.
I think that is jenkins issue. If you class extends hudson.tasks.Builder then it won't give you logged use information by invoking method User.Current() instead it will give you SYSTEM user. But if you invoke same method from other classes which should be extend Jenkins class then it may get you logged user.
In my case, I have created another class which extend hudson.model.ManagementLink and annotated with hudson.Extension annotation. In this class User.Current() give me logged user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With