Jenkins 管道获取拒绝者名称而不是用户 ID
Jenkins Pipeline Get Rejecter Name instead of user id
我已按照以下 link 拒绝/批准部署请求。但如果我拒绝部署,我只能获得用户 ID。如何获取用户名?
def user = err.getCauses()[0].getUser()
试试这个:
import hudson.model.Cause
import hudson.tasks.Mailer
import hudson.model.User
def name = cause.getUserName()
println "name is ${name}"
def jenkins_id = cause.getUserId()
println "jenkins_id is ${jenkins_id}"
User u = User.get(jenkins_id)
def umail = u.getProperty(Mailer.UserProperty.class)
def email = umail.getAddress()
println "email is ${email}"
您可能需要阅读 User
class 的 JavaDocs 以查看该名称是否可用。
我找到了解决方案如下
def user = err.getCauses()[0].getUser().getDisplayName()
我已按照以下 link 拒绝/批准部署请求。但如果我拒绝部署,我只能获得用户 ID。如何获取用户名?
def user = err.getCauses()[0].getUser()
试试这个:
import hudson.model.Cause
import hudson.tasks.Mailer
import hudson.model.User
def name = cause.getUserName()
println "name is ${name}"
def jenkins_id = cause.getUserId()
println "jenkins_id is ${jenkins_id}"
User u = User.get(jenkins_id)
def umail = u.getProperty(Mailer.UserProperty.class)
def email = umail.getAddress()
println "email is ${email}"
您可能需要阅读 User
class 的 JavaDocs 以查看该名称是否可用。
我找到了解决方案如下
def user = err.getCauses()[0].getUser().getDisplayName()