如何获取当前 Jenkins 用户的电子邮件地址以在 groovy 脚本中使用 [英] How to get e-mail address of current Jenkins user to use in groovy script

查看:38
本文介绍了如何获取当前 Jenkins 用户的电子邮件地址以在 groovy 脚本中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为新的 Jenkins 工作流插件创建了一个 groovy 脚本,https://github.com/jenkinsci/工作流插件.我希望它在下一步需要输入时向开始工作的用户发送邮件.我尝试搜索 API,但找不到任何有关获取用户电子邮件地址的信息.

I've created a groovy script for the new Jenkins Workflow Plugin, https://github.com/jenkinsci/workflow-plugin. I want it to send a mail to the user who started the job when it needs input for the next step. I've tried to search the API but I can't find anything about getting the users email address.

我会想到这样的事情.

import hudson.model.User
def user = User.current()
def mailAddress = user.getMailAddress()

有没有办法在 groovy 中获取当前 Jenkins 用户的地址?

Is there a way to get the current Jenkins user' address in groovy?

推荐答案

我找到了办法:

import hudson.model.AbstractProject
import hudson.tasks.Mailer
import hudson.model.User

def item = hudson.model.Hudson.instance.getItem(env.JOB_NAME) 
def build = item.getLastBuild()
def cause = build.getCause(hudson.model.Cause.UserIdCause.class)
def id = cause.getUserId()
User u = User.get(id)
def umail = u.getProperty(Mailer.UserProperty.class)
print umail.getAddress()

这篇关于如何获取当前 Jenkins 用户的电子邮件地址以在 groovy 脚本中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆