“项目覆盖率设置为 0%"– 詹金斯的 JaCoCo 和 Sonar 与 Ant [英] "Project coverage is set to 0%" – JaCoCo and Sonar in Jenkins with Ant

查看:23
本文介绍了“项目覆盖率设置为 0%"– 詹金斯的 JaCoCo 和 Sonar 与 Ant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将工作从单台 Hudson 机器转移到多从机 Jenkins 环境,现在 JaCoCo 覆盖不再有效.

I moved my job from a single Hudson machine to a multi-slave Jenkins environment, and now JaCoCo coverage no longer works.

工作(旧):哈德逊 2.0.1,詹金斯声纳插件 1.7.1,声纳 2.1.2

WORKING (old): Hudson 2.0.1, Jenkins Sonar Plugin 1.7.1, Sonar 2.1.2

破损(新):詹金斯 1.446,詹金斯声纳插件 1.7.2,声纳 2.1.2

BROKEN (new): Jenkins 1.446, Jenkins Sonar Plugin 1.7.2, Sonar 2.1.2

我的 Hudson 工作称为 Pinnacle,它曾经在一台 Hudson 服务器上与 Sonar 在同一台机器上运行.我通过执行以下操作来设置我的 (NO MAVEN) 构建.

My Hudson job is called Pinnacle and it used to run on a single Hudson server with Sonar on the same machine. I set up my (NO MAVEN) build by doing the following.

1) 向我的 build.xml 添加了一个名为 test-with-coverage

1) Added an Ant target to my build.xml called test-with-coverage

2) 使用以下属性将 Hudson 中的 Pinnacle 作业配置为调用独立声纳分析":

2) Configured the Pinnacle job in Hudson to "invoke standalone Sonar Analysis" with these properties:

sonar.projectKey=com.skyboximaging:pinnacle
sonar.projectName="Pinnacle"
sonar.projectVersion=1.0
sources=Pinnacle/src/java
tests=Pinnacle/test/java
binaries=Pinnacle/classes
sonar.jacoco.reportPath=Pinnacle/jacoco.exec
sonar.jacoco.antTargets=test-with-coverage

(请注意,代码已检出到 Jenkins 作业工作区的 Pinnacle 目录中.)

(Note that the code is checked out into Pinnacle directory in the Jenkins job workspace.)

3) 配置声纳常规设置"以使用 JaCoCo 进行代码覆盖

3) Configured Sonar "general settings" to use JaCoCo for code coverage

一切都很顺利!

但是在新的 Jenkins 环境中,我在 Jenkins 构建输出中看到了这个错误:

But in the new Jenkins environment, I see this error in the Jenkins build output:

23:15:17.863 INFO  Sensor JaCoCoSensor...
23:15:17.868 INFO  Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/workspace/Pinnacle/Pinnacle/jacoco.exec

该文件在运行构建的从属服务器上不存在.(目录/var/lib/jenkins/workspace/Pinnacle/Pinnacle 确实存在.)

That file does not exist on the slave where the build ran. (The directory /var/lib/jenkins/workspace/Pinnacle/Pinnacle does exist.)

所有其他传感器(FindBugs、PMD 等)似乎工作正常.只是 JaCoCo 坏了.

All other sensors (FindBugs, PMD, etc) appear to be working OK. Just JaCoCo is broken.

Sonar/JaCoCo 甚至可以在多从属 Jenkins 环境中工作吗?

Does Sonar/JaCoCo even work in a multi-slave Jenkins environment?

我怀疑 Ant 任务 test-with-coverage 没有运行.Sonar 如何定位 build.xml?新旧安装有什么不同?

I suspect that the Ant task test-with-coverage is not getting run. How does Sonar locate the build.xml? And what is different between old and new installations?

推荐答案

我最近设置并成功让 Sonar 和 Jacoco 一起运行.由于我最近关注该主题,因此我想我会检查 stackoverflow 是否存在类似问题并提供帮助.我从 Jacoco 获得结果,但发现除了您在帖子中列出的属性之外,您还必须明确设置以下参数:

I've recently setup and successfully got Sonar and Jacoco running together. Since I'm recent with the topic, I figured I'd check on stackoverflow for similar issues and help out. I am getting results from Jacoco, but found you had to explicitly set the following parameters in addition to the properties you've listed in your post:

sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=tests/test-reports

如果您希望能够使用 sonar.jacoco.reportPath 属性,则必须设置 sonar.core.codeCoveragePlugin=jacoco.否则,您将不得不使用 sonar.jacoco.itReportPath 属性.但是,我建议只设置 codeCoveragePlugin 和 reportPath 属性.否则,它不会显示在声纳的默认覆盖小部件下.请注意,您不能同时使用默认覆盖工具和 jacoco.它必须是其中之一.我决定使用 Jacoco.

You have to set sonar.core.codeCoveragePlugin=jacoco if you want to be able to use the sonar.jacoco.reportPath property. Otherwise, you will have to use the sonar.jacoco.itReportPath property. However, I recommend just setting the codeCoveragePlugin and reportPath properties. Otherwise, it won't display under the default coverage widget in sonar. Please make note, you cannot use the default coverage tool and jacoco together. It has to be one or the other. I decided to use Jacoco.

您的 ant 目标必须配置为在运行声纳任务之前生成 jacoco.exec 结果:

Your ant target must be configured to generate the jacoco.exec results prior to running the sonar tasks:

<jacoco:coverage enabled="${tests.code.coverage}" destfile="${jacoco.exec.dest}">
  <junit fork="yes" printsummary="withOutAndErr" dir="${tests.working.dir}">
  ...

如果您在声纳之前运行 junit,请务必告诉声纳重复使用报告和任何 sunfire 报告,也就是说,如果您在声纳之外运行 junit:

Be sure to tell sonar to reuse reports and any sunfire reports if you're running junit before sonar, that is if you're running junit outside of sonar:

sonar.dynamicAnalysis=reuseReports
sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
sonar.surefire.reportsPath=tests/test-reports

无论出于何种原因,如果您需要更详细的调试,请使用以下属性:

For whatever reason, if you need more verbose debugging, use the following property:

sonar.verbose=true

sonar.verbose=true

这篇关于“项目覆盖率设置为 0%"– 詹金斯的 JaCoCo 和 Sonar 与 Ant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆