简体   繁体   English

在Jenkins中通过邮件共享格式化的报告

[英]Sharing formatted reports over the mail in Jenkins

What's Working - We are currently using testng emailable format and allure to generate formatted reports for our current test execution. 什么工作 -我们目前正在使用testng电子邮件发送的格式和allure来产生我们目前的测试执行格式化的报告。 These are working fine with our local. 这些与我们当地人的工作很好。 The /target/report structure can be seen in the image to depict 2 different folders for allure(/site) and testng(/surefire) reports respectively : 在图像中可以看到/target/report结构,分别描绘了2个不同的文件夹,用于分别显示allure(/ site)和testng(/ surefire)报告: 在此处输入图片说明


Trying to - While we are trying to implement a CI using Jenkins using the same steps as in our local, the tests are executed fine and the respective reports are getting generated as well. 尝试 -在我们尝试使用Jenkins通过与本机中相同的步骤来实施CI时,测试执行得很好,并且还生成了相应的报告。

Using TestNG plugin and specifying the pattern **/target/surefire-reports/testng-results.xml works just fine to display the testNG result graph. 使用TestNG插件并指定模式**/target/surefire-reports/testng-results.xml可以很好地显示testNG结果图。

Also using the Email ext plugin I can attach the .html reports to the mail sent to the recipients specifying the attachment field details as : **/target/surefire-reports/emailable-report.html, **/target/surefire-reports/index.html 同样使用Email ext插件,我可以将.html报告附加到发送给收件人的邮件中,并指定附件字段详细信息,例如: **/target/surefire-reports/emailable-report.html, **/target/surefire-reports/index.html


What doesn't work - We end up getting emails with HTML reports but these are not formatted, probably because all the CSS linked to these are left behind. 什么不起作用 -我们最终收到带有HTML报告的电子邮件,但这些电子邮件未格式化,可能是因为所有与这些报告链接的CSS都被遗忘了。 Is there a way to overcome this? 有办法克服吗?


Note - Have tried these: 注意-尝试过以下方法:

  1. Attaching all the .css files along with .html file in attachments but, one that's brute force and second it still doesn't work. 将所有.css文件和.html文件一起附加在附件中,但是那种蛮力的方法,其次仍然无效。

  2. One way also is to scp the report (/target) directory to another host from Jenkins instance and share the path of the reports on that machine over the email notification and get the formatted reports shared. 一种方法也就是scp报告(/目标)目录,从詹金斯实例另一台主机,并通过电子邮件通知分享这台机器上的报告的路径,并得到共享格式化的报告。 But then this needs an additional resource and dependency on it, that we would want to avoid. 但是,这需要额外的资源和对它的依赖,我们希望避免这种情况。

  3. While posting this, I see an HTML publisher plugin that seems to be doing something similar. 发布此消息时,我看到一个HTML Publisher插件似乎在做类似的事情。 Tried installing the same and use it. 尝试安装相同并使用它。 But I am assuming since we are using Jenkins 2.6 and the plugin note reads 但我假设,因为我们使用的是Jenkins 2.6 ,并且插件说明显示为

Starting in versions 1.625.3 and 1.641, Jenkins restricted what kind of content could be displayed when serving static files. 从版本1.625.3和1.641开始,詹金斯(Jenkins)限制了在提供静态文件时可以显示哪种内容。 This can impact how HTML files archived using this plugin are displayed. 这会影响使用此插件归档的HTML文件的显示方式。 See Configuring Content Security Policy for more information. 有关更多信息,请参见配置内容安全策略。

We are not getting the option to Publish HTML Reports in the post build actions. 在后期构建操作中,我们没有选择“ Publish HTML Reports的选项。


Any suggestions are more than welcome and please do ask for any more information required over this. 我们非常欢迎您提出任何建议,并要求提供更多有关此方面的信息。

Edit : Adding to the Note 2 above, the Jenkins instances used in our setup are docker slaves, apparently making the reports or targets generated not being persistent. 编辑 :添加到上面的注释2中,在我们的设置中使用的Jenkins实例是docker slaves,显然使生成的报告或目标不是持久性的。

Here's what you can consider doing. 这是您可以考虑做的事情。

Option 1 选项1

  1. Build an implementation for IExecutionListener wherein you create the logic to basically zip up all the reports that you want and have it sent as an e-mail. 构建IExecutionListener的实现,在其中创建逻辑以基本上压缩所有想要的报告并将其作为电子邮件发送。
  2. Wire in this listener and that should take care. 连接此侦听器,应该小心。

PS : Currently implementations of IExecutionListener are invoked "before" the report generation phase. PS:当前,IEXecutionListener的实现是在报告生成阶段之前“调用”的。 I have changed this as part of this commit. 我已将此更改作为提交的一部分。 So if you would like to go ahead with this approach then you might want to wait till TestNG goes out with a new release (should happen in a couple of days ) 因此,如果您想继续使用此方法,则可能要等到TestNG发行新版本(应该在几天内完成)

Option 2 选项2

  • Build a wrapper reporter (which implements IReporter ) and wire in ONLY this reporter. 构建一个包装报告器(实现IReporter ),并仅插入该报告器。
  • Within this reporter, you explicitly instantiate all the reporters that you would like to be called in for your reporting phase. 在此报告程序中,您显式实例化了要在报告阶段调用的所有报告程序。 See below for a possible sample. 请参阅下面的示例。
public class ChainedReporter implements IReporter {

    private List<IReporter> reporters = new ArrayList<>;

    public ChainedReporter() {
        reporters.add(new FooReporter() );//Here FooReporter is a custom reporter. Replace it with yours.
        reporters.add(new BarReporter() );//Here BarReporter is a custom reporter. Replace it with yours.
    }
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
        for (IReporter reporter : reporters) {
            reporter.generateReport(xmlSuites, suites, outputDirectory);
        }
        //By now we have ensured that all the reporting logic has been triggered and we have reports generated.
        zipReports(); //  This method would take care of creating zipped files of all the reports.
        emailReports(); // This emthod would take care of emailing the actual reports.

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM