我希望在构建后脚本中获取构建请求者的用户名和/或电子邮件地址。
Sidenote:我想要请求者,这样我就可以在email-ext插件的预发送脚本中动态地设置邮件发送方的邮件发送方。
AbstractBuild内置了对AbstractBuild.getCulprits()和AbstractBuild.hasParticipant(User user)的支持,但我找不到检索请求者的方法。我在参考表中也找不到对User类的任何有用的引用。
发布于 2014-08-18 12:59:01
我设法通过构建的Cause ( 在这个答案中推荐 )来解决这个问题。
在构建的原因中可以找到构建请求者的原因是非常有意义的:不是每个构建都是由用户直接触发的。如果是由用户触发的,则生成原因列表包含一个Cause.UserIdCause,其中包含用户的id和名称。
这段代码片段对我有用。它通过原因从构建中提取用户名,并设置from和ReplyTo头。我在电子邮件分机 Jenkins插件的预发送脚本中使用它。
import javax.mail.internet.InternetAddress
cause = build.getCause(hudson.model.Cause.UserIdCause.class);
username = cause.getUserName()
id = cause.getUserId()
email = new InternetAddress(String.format("%s <%s@example.com>", username, id))
msg.setFrom(email)
msg.setReplyTo(email);https://stackoverflow.com/questions/25362820
复制相似问题