Jenkins 管道获取拒绝者名称而不是用户 ID

Jenkins Pipeline Get Rejecter Name instead of user id

我已按照以下 link 拒绝/批准部署请求。但如果我拒绝部署,我只能获得用户 ID。如何获取用户名?

def user = err.getCauses()[0].getUser()

https://support.cloudbees.com/hc/en-us/articles/226554067-Pipeline-How-to-add-an-input-step-with-timeout-that-continues-if-timeout-is-reached-using-a-default-value?mobile_site=true

试试这个:

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