将 Jenkins 控制台输出作为 HTML 电子邮件发送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27410378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send Jenkins console output as HTML email
提问by Sumitk
I don't know if this is at all possible but still asking here to see if anyone has tried/thought about it.
我不知道这是否可能,但仍然在这里询问是否有人尝试过/考虑过它。
I have a build running that when fails echo out html code as given below. I want to send this html as an email to all the recipients.
我有一个正在运行的构建,当失败时回显如下 html 代码。我想将此 html 作为电子邮件发送给所有收件人。
Currently when I use the simple email plugin then the whole console output is sent as an email which contains all these html tags (not at all readable). Then I installed the Email Ext plugin but I am not sure if the pre-send script can read my console output and send email. Has anyone tried it? Is it worth spending time on it or should I just modify the output to display formatted text?
目前,当我使用简单的电子邮件插件时,整个控制台输出将作为电子邮件发送,其中包含所有这些 html 标签(根本不可读)。然后我安装了 Email Ext 插件,但我不确定预发送脚本是否可以读取我的控制台输出并发送电子邮件。有没有人试过?值得花时间在上面还是我应该修改输出以显示格式化文本?
This build is for internal tools and I can't create a .html file or send the link to the .html file as email because the path is behind firewall.
此版本用于内部工具,我无法创建 .html 文件或将指向 .html 文件的链接作为电子邮件发送,因为路径位于防火墙后面。
I don't know if this is supported at all but is it possible that the console output shows html output?
我不知道这是否受支持,但控制台输出是否可能显示 html 输出?
Thanks for the help!
谢谢您的帮助!
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<table class="gridtable">
<thead>
<tr>
<th>Service Checked</th>
<th>Status</th>
<th>Response</th>
</tr>
</thead>
<tbody>
<tr>
<td>canary</td>
<td>Success</td>
<td>Please override the check() method</td>
</tr>
<tr>
<td style="color: red;"><strong>www.mysite.com</strong></td>
<td style="color: red;">Failure</td>
<td>Ping to https://www.mysite.com/canary?from=here FAILED</td>
</tr></tbody></table>
回答by Slav
Email Ext plugin works just fine with HTML. It's up to your email client to parse HTML (but then again, most these days do).
Email Ext 插件与 HTML 配合得很好。解析 HTML 取决于您的电子邮件客户端(但话说回来,现在大多数情况下都是如此)。
The question is: how does your build output this HTML above? Does it output it to file? Does it display it in Console Output?
问题是:你的构建如何输出上面的这个 HTML?它是否将其输出到文件?它是否显示在控制台输出中?
If the text is in console output, use:
如果文本在控制台输出中,请使用:
<pre>${BUILD_LOG_EXCERPT, start="Regex-for-start", end="Regex-for-end"}</pre>
<pre>${BUILD_LOG_EXCERPT, start="Regex-for-start", end="Regex-for-end"}</pre>
The <pre>
tags are to preserve spacing/formatting.
The start
and end
regular expressions are to identify the "starting line" from which to start displaying log, and the "ending line" at which to stop displaying log.
该<pre>
标签是保持间距/格式化。
在start
和end
正则表达式识别“起跑线”从开始显示日志,而“结束行”在其停止显示日志。
Note that the start
and end
lines themselves are excluded. So, in your build, put a header and footer lines just before and just after your html output, and use them here.
请注意,start
和end
行本身被排除在外。因此,在您的构建中,在您的 html 输出之前和之后放置一个页眉和页脚行,并在此处使用它们。
For reference, in the email-ext configuration, click the Content Referencequestion mark icon ?
作为参考,在 email-ext 配置中,单击Content Reference问号图标?
回答by Sumitk
So this is how I solved it with the help of @Slav.
Jenkins job was running this script:
詹金斯工作正在运行这个脚本:
<?php
echo "start-here\n";
echo "<html><body><table border=1>
<tr><td>yello1111</td><td>11111bbbbbbb</td></tr>
<tr><td>yelloooo</td><td>bbbbbbb</td></tr>
</table></body></html>";
echo "end-here\n";
The job was configured with email-extand in the Add post-build action->Editable Email Notification -> Default ContentI put the following:
该作业使用email-ext进行配置,并在Add post-build action->Editable Email Notification -> Default Content我输入以下内容:
${BUILD_LOG_EXCERPT, start="\b(start-here)\b", end="\b(end-here)\b"}
This send the email as html content and not the text of html.
这会将电子邮件作为 html 内容而不是 html 文本发送。
回答by Ajeet Khan
Go to "Manage-jenkins"->"configure system" Than on the "Extended E-mail Notification" settings, put the below line in "default content" text-area
转到“Manage-jenkins”->“configure system” 比在“Extended E-mail Notification”设置上,把下面这行放在“default content”文本区域
<pre>${BUILD_LOG, maxLines=9999, escapeHtml=false}</pre>
回答by Robert
Even if you are behind a firewall, you should be able to write an HTML file to the workspace (from your script).
This file you can then send as/include in the mail body using
${FILE,path="PATH"}
.
即使您在防火墙后面,您也应该能够将 HTML 文件写入工作区(从您的脚本)。然后,您可以将此文件作为/包含在邮件正文中使用
${FILE,path="PATH"}
.