我需要使用groovy访问Jenkins中的用户详细信息。这就是我的做法。
cause = build.getCause(hudson.model.Cause.UserIdCause.class);
username = cause.getUserName()
User id = User.get(cause.getUserId())
println("user id :: "+ cause.getUserId())
println("user name :: "+ username)
println("email :: "+ id.getProperty(Mailer.UserProperty.class).getAddress())
但是,我也需要API令牌和密码,我可以手动访问用户-
谢谢!
我找到了解决办法-
import hudson.model.*
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import hudson.model.AbstractProject
import hudson.tasks.Mailer
import hudson.model.User
cause = build.getCause(hudson.model.Cause.UserIdCause.class);
username = cause.getUserName()
User id = User.get(cause.getUserId())
println("user id :: "+ cause.getUserId())
println("user name :: "+ username)
println("email :: "+ id.getProperty(Mailer.UserProperty.class).getAddress())
println("API Token :: "+ id.getProperty(jenkins.security.ApiTokenProperty.class).getApiToken())