3

我在各个地方都看到过这种问题,但还没有找到真正的答案。

有谁知道如何使用 html.jelly 模板使构建日志显示在正文中,而不是全部一起运行,并且实际上用换行符分隔每一行?

我很确定答案在于模板需要进行某种更改,但我不知道从哪里开始。

现在我在我的电子邮件中收到了这个:

    [copy] Copying 1 file to /opt/hybris/hybris/bin/ext-channel/cscockpit/resources/localization [mkdir] Created dir: /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc [echo] [jspcompile] generating.. [echo] [jspcompile] touching jsp files [echo] [jspcompile] compiling.. /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc [yjavac] Compiling 209 source files to /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc [touch] Creating /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc/jspcompile_touch [stopwatch] [build: 36.436 sec] server: [echo] [echo] Configuring server at /opt/hybris/hybris/bin/platform/tomcat-6 [echo] Using config set at /opt/hybris/hybris/config/tomcat [echo] [copy] Copying 8 files to /opt/hybris/hybris/bin/platform/tomcat-6 [copy] Copying 6 files to /opt/hybris/hybris/bin/platform/tomcat-6 [copy] Copying 1 file to /opt/hybris/hybris/bin/platform/tomcat-6/lib [java] Process not found [java] shutting down hybris registry.. all: [echo] Build finished on 24-March-2014 07:09:01. [echo] BUILD SUCCESSFUL Total time: 42 seconds SSH: EXEC: completed after 59,838 ms SSH: Disconnecting configuration [Dev-trunk] ... SSH: Transferred 3 file(s) Email was triggered for: Success Sending email for trigger: Success 

但我希望它看起来像这样......

[copy] Copying 1 file to /opt/hybris/hybris/bin/ext-channel/cscockpit/resources/localization 
[mkdir] Created dir: /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc 
echo] 
jspcompile] generating.. 
[echo] 
[jspcompile] touching jsp files 
[echo] 
[jspcompile] compiling.. /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc [yjavac] Compiling 209 source files to /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc [touch] Creating /opt/hybris/hybris/bin/platform/tomcat-6/work/Catalina/localhost/hmc/jspcompile_touch 
[stopwatch] 
[build: 36.436 sec] server: 
[echo] 
[echo] Configuring server at /opt/hybris/hybris/bin/platform/tomcat-6 
[echo] Using config set at /opt/hybris/hybris/config/tomcat 
[echo] 
[copy] Copying 8 files to /opt/hybris/hybris/bin/platform/tomcat-6 
[copy] Copying 6 files to /opt/hybris/hybris/bin/platform/tomcat-6 
[copy] Copying 1 file to /opt/hybris/hybris/bin/platform/tomcat-6/lib 
[java] Process not found 
[java] shutting down hybris registry.. all: 
[echo] Build finished on 24-March-2014 07:09:01. 
[echo] BUILD SUCCESSFUL Total time: 42 seconds SSH: EXEC: completed after 59,838 ms SSH: Disconnecting configuration 
[Dev-trunk] ... SSH: Transferred 3 file(s) Email was triggered for: Success Sending email for trigger: Success 
4

1 回答 1

7

抱歉让您久等了。今天我可以访问我的 jenkins 服务器,我尝试了 Jelly 模板,它工作正常。

首先ext-mail插件的WIKI非常好用,这里是链接:ext-mail wiki

我的jenkins的安装路径和你的一样:/var/lib/jenkins/,但是我没有找到JELLY模板文件html.jelly,我使​​用来自WIKI的文件,这里是链接:html.jelly

现在我将展示我所做的以及得到的结果:

  • 其实我把模板文件html.jelly放在/var/lib/jenkins/email-templates,注意根据WIKI,你需要在你的jenkins安装文件夹下创建文件夹email-templates,这样ext-mail插件in 可以访问模板文件。我没有尝试过你指定的路径,所以我不知道如果我将html.jelly放在目录下它是否仍然有效:/var/lib/jenkins/plugins/email-ext/WEB-INF/lib /hudson/plugins/emailext/模板。

  • 将 html.jelly 重命名为 html_my.jelly。

  • 修改 html_my.jelly,注释以下 3 行,以便控制台日志始终显示。
<!--
<j:getStatic var="resultFailure" field="FAILURE" className="hudson.model.Result"/>
<j:if test="${build.result==resultFailure}">
-->
<TABLE width="100%" cellpadding="0" cellspacing="0">
<TR><TD class="bg1"><B>控制台输出</B></TD></TR>
<j:forEach var="line" items="${build.getLog(100)}"><TR><TD class="console">${line}</TD></TR></j:对于每个>
</表>
<BR/>
<!-- </j:if> -->
  • Jenkins -- 管理 Jenkins -- 配置系统 -- 扩展电子邮件通知。将“默认内容类型”设置为“HTML(text/html)”,我这里设置的默认内容为${JELLY_SCRIPT, template="html_my"},我想我们可以在 Job 的配置中设置 Default Content 也可以。请参阅此处的图片: 詹金斯系统配置

  • 在您的作业配置中,您还需要将内容类型修改为“HTML (text/html)”,并且您需要指定触发器类型。请参阅配置作业的图像:配置您的工作

如您所见,下图是我临时工作的电子邮件内容,希望这对您有所帮助,如果您有更多问题,请告诉我。 电子邮件内容示例

顺便说一句,使用groovy模板也很棒,你可以试试!

于 2014-03-27T06:14:45.503 回答