8

I need get the current log in user in Jenkins, I am using a Groovy parameter but I don't know how to get that,

Thanks,

4
  • 1
    Isn't it User.current()? Commented Jun 11, 2014 at 15:36
  • Yes is it, thanks man I have several days searching that Commented Jun 11, 2014 at 15:41
  • Added as an answer :-) Have fun! Commented Jun 11, 2014 at 15:48
  • 2
    returns SYSTEM ! Commented Jun 18, 2018 at 14:33

3 Answers 3

8

You should be able to call:

import hudson.model.User ... User.current() 

From a groovy script to get the current user :-)

Sign up to request clarification or add additional context in comments.

1 Comment

In script pipeline, it returns SYSTEM
3

def user = build.causes[0].userId

1 Comment

Since build by itself doesn't exist it should be currentBuild.rawBuild.causes[0].userId, but thanks for pointing me in the right direction, User.current() does indeed return 'SYSTEM'. Have some points.
1
import hudson.model.* def job = Jenkins.getInstance().getItemByFullName(env.JOB_BASE_NAME, Job.class) def build = job.getBuildByNumber(env.BUILD_ID as int) def userId = build.getCause(Cause.UserIdCause).getUserId() def user = User.current() println(user); println(userId); ----- this is the output [Pipeline] echo (hide) SYSTEM [Pipeline] echo eefrat [Pipeline] echo eefrat 

2 Comments

Welcome to Stack Overflow. Please add a few words to help explain your answer.
I'm not sure I understood... userId gives you the user who triggered the build or the user who's logged in?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.