提问者:小点点

如何访问用户API令牌在Jenkins使用groovy?


我需要使用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令牌和密码,我可以手动访问用户-

谢谢!


共1个答案

匿名用户

我找到了解决办法-

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())