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

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

问题描述

我为新的Jenkins Workflow Plugin创建了一个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.

我会想到类似这样的事情。

I would think of something like this.

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?

推荐答案

我找到了一个方法:

I found a way:

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天全站免登陆