我在很多地方都看到过这种问题,但还没有找到真正的答案。
有谁知道如何使用 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
最佳答案
抱歉让您久等了。今天我可以访问我的 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插件可以访问模板文件。我没有尝试过你指定的路径,所以我不知道如果我把 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>CONSOLE OUTPUT</B></TD></TR> <j:forEach var="line" items="${build.getLog(100)}"><TR><TD class="console">${line}</TD></TR></j:forEach> </TABLE> <BR/> <!-- </j:if> -->
Jenkins -- 管理 Jenkins -- 配置系统 -- 扩展电子邮件通知。 设置“默认内容类型”为“HTML(text/html)”,我这里设置默认内容为
${JELLY_SCRIPT, template="html_my"}
,我想我们可以设置作业配置中的默认内容也将起作用。请参阅此处的图片:在您的作业配置中,您还需要将内容类型修改为“HTML (text/html)”,并且您需要指定触发器类型。引用配置作业的图像:
如您所见,下图是我临时工作的邮件内容,希望对您有所帮助,如果您有更多问题,请告诉我。
对了,使用groovy模板也很精彩,你可以试试!
关于email - Jenkins Email-ext 插件构建日志全部在一行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22612440/