如何在Groovy参数上获取Jenkins中的当前会话用户

时间:2014-06-11 14:19:05

标签: groovy jenkins

我需要在Jenkins中获取当前登录用户,我使用的是Groovy参数,但我不知道如何获取,

谢谢,

3 个答案:

答案 0 :(得分:5)

您应该可以致电:

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

从groovy脚本获取当前用户: - )

答案 1 :(得分:3)

def user = build.causes [0] .userId

答案 2 :(得分: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