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

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

问题描述

我将工作从一台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, Jenkins声纳插件1.7.1, 声纳2.1.2

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

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

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

我的Hudson作业称为Pinnacle,它过去曾与同一台计算机上的Sonar一起在单个Hudson服务器上运行.我通过执行以下操作设置了我的(否")构建.

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)在哈德森(Hadson)中配置品尼高(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)配置Sonar常规设置"以使用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甚至可以在多从属詹金斯环境中工作吗?

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属性.否则,它将不会显示在声纳的默认coverage小部件下.请注意,您不能同时使用默认覆盖工具和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.

您的蚂蚁目标必须配置为在运行声纳任务之前生成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,即在声纳之外运行junit,请确保告诉声纳重用报告和所有sunfire报告:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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