I've created a groovy script for the new Jenkins Workflow Plugin, https://github.com/jenkinsci/workflow-plugin. I want it to send a mail to the user who started the job when it needs input for the next step. I've tried to search the API but I can't find anything about getting the users email address.
I would think of something like this.
import hudson.model.User
def user = User.current()
def mailAddress = user.getMailAddress()
Is there a way to get the current Jenkins user' address in groovy?
You can access the object of the current user with the method
current()
The email address can be retrieved in the same way as to what you have done in your answer.
You can get the author name and then use it for an example on a mailing registry or something like that:
If you have access to the
build
variable in the Java code of your plugin (for instance in thesetUp()
method of the class that extendsBuildWrapper
), you can get the currently logged user this way :I have not been able to get the logged user using
User.current().getId()
, it always returned me 'SYSTEM
'.Hope it helps!
I found a way: