在 jenkins Groovy 电子邮件中包含构建请求用户

问题描述 投票:0回答:2

构建完成后,我使用 mail-ext-plugin(Jenkins 电子邮件扩展插件)向某些用户发送电子邮件。我想在该电子邮件中包含开始(请求)构建的用户。我已经尝试过建议here但是,这似乎不起作用我刚刚收到此错误。

Error in script or template: groovy.lang.MissingPropertyException: No such property: CAUSE for class: SimpleTemplateScript4
email groovy jenkins jenkins-plugins
2个回答
1
投票

经过大量搜索,我在 Jenkins wiki 上找到了有关 jelly 使用的页面(here)。此页面上有一个链接,其中包含所有可用的类。我能够找到原因类并使用这个很棒的example来帮助我在代码中实现它。我添加了

<%
    for (hudson.model.Cause cause : build.causes) {
%>
        ${cause.shortDescription}
<%
    }
%>

产生了 -

Started by user Matthew Armstrong

0
投票

为了避免

groovy.lang.MissingPropertyException: No such property: Cause for class
,您可以尝试
import hudson.model.Cause
,甚至更好 - 直接调用
currentBuild.getBuildCauses()
,而不是导入 'Cause' 类。

例如:

def buildUserName = currentBuild.getBuildCauses()[0].userName
def buildDescription = currentBuild.getBuildCauses()[0].shortDescription
© www.soinside.com 2019 - 2024. All rights reserved.