SonarQube分析未显示代码覆盖率 [英] SonarQube Analysis not showing code coverage

查看:159
本文介绍了SonarQube分析未显示代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jenkins项目来对我的NodeJS项目进行SonarQube分析.我添加了istanbul作为对我项目的package.json的依赖.在Jenkins构建配置中,首先我运行一个shell脚本:

I have a Jenkins project to do SonarQube analysis of my NodeJS project. I added istanbul as a dependency to my project's package.json. In the Jenkins build configuration, first I run a shell script:

cd ./project-name
npm install
node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha path-to-unit-tests
node_modules/.bin/istanbul report cobertura
cd ..

这将安装依赖项,运行测试并生成代码覆盖率报告,并生成cobertura-coverage.xml文件.

This installs the dependencies, runs the tests and generates a code coverage report and generates a cobertura-coverage.xml file.

在执行shell脚本之后,我运行具有以下属性的Invoke Standalone SonarQube Analysis来覆盖代码:

After the shell script, I run a Invoke Standalone SonarQube Analysis with the following properties for code coverage:

sonar.java.coveragePlugin=cobertura
sonar.dynamicAnalysis=reuseReports
sonar.cobertura.reportPath=./project-name/coverage/cobertura-coverage.xml

Jenkins作业通过SonarQube仪表板成功运行,该仪表板描述了项目的各种内容,例如代码行,技术债务,问题等.但是,单元测试的代码覆盖率并未显示在SonarQube仪表板上.我确保仪表板具有单元测试"小部件.

The Jenkins job runs successfully with a SonarQube dashboard describing various things such as the lines of code, technical debt, issues and so on for the project. But the code coverage for the unit tests doesn't show up on the SonarQube dashboard. I made sure that the dashboard has the Unit Tests widget.

Version of SonarQube server: 5.2
Version of JavaScript plguin used on SonarQube: 2.9
Version of Cobertura plugin used on SonarQube: 1.6.3
Version of Cobertura plugin used on Jenkins: 1.9.7
Version of NodeJS plugin used on Jenkins: 0.2.1

我验证了工作空间确实具有cobertura-coverage.xml文件.还检查了构建控制台日志,没有发现错误.我还尝试过使用LCOV格式来提高代码覆盖率:

I verified that the workspace does have the cobertura-coverage.xml file. Also checked the build console logs and found no bugs. I have also tried pushing the code coverage using LCOV format before:

sonar.dynamicAnalysis=reuseReports
sonar.javascript.lcov.reportPath=./project-name/coverage/lcov.info

即使覆盖报告确实在Jenkins工作区中生成,该报告也不会发布到SonarQube.我查看了工作区的内容并进行了验证.控制台日志显示生成的覆盖率报告.也尝试过

The report doesn't get published to SonarQube even though the coverage report does get generated in Jenkins workspace. I looked at the workspace contents and verified. The console logs show the coverage report getting generated. Also tried

sonar.dynamicAnalysis=reuseReports
sonar.javascript.lcov.reportPath=project-name/coverage/lcov.info

sonar.dynamicAnalysis=reuseReports
sonar.cobertura.reportPath=project-name/coverage/cobertura-coverage.xml

无济于事.我还分别两次重启了Jenkins和SonarQube服务器.在StackOverflow和其他地方查看了许多类似的问题,但没有找到任何有效的方法.

to no avail. I also restarted the Jenkins and SonarQube servers 2 times each. Looked at many similar questions on StackOverflow and elsewhere but didn't find anything that works.

如果我添加构建后操作Publish Cobetura Coverage Report并在Cobertura xml report pattern字段中指定cobetura-coverage.xml文件的路径,则代码覆盖率报告确实会在Jenkins中发布.

If I add a post-build action Publish Cobetura Coverage Report and specify the path to the cobetura-coverage.xml file in the Cobertura xml report pattern field, the code coverage report does get published in Jenkins.

看了SonarQube中的后台任务日志,发现一个异常.

Looked at the background task logs in SonarQube and saw an exception.

java.lang.IllegalStateException: Cannot persist sources of project-key:project-name/node_modules/jscs/jscs-browser.js
at     org.sonar.server.computation.step.PersistFileSourcesStep$FileSourceVisitor.visitFile(PersistFileSourcesStep.java:132) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visitNode(DepthTraversalTypeAwareCrawler.java:72) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visit(DepthTraversalTypeAwareCrawler.java:44) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visitChildren(DepthTraversalTypeAwareCrawler.java:91) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visit(DepthTraversalTypeAwareCrawler.java:47) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visitChildren(DepthTraversalTypeAwareCrawler.java:91) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler.visit(DepthTraversalTypeAwareCrawler.java:47) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.step.PersistFileSourcesStep.execute(PersistFileSourcesStep.java:89) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:39) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.taskprocessor.report.ReportTaskProcessor.process(ReportTaskProcessor.java:53) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.taskprocessor.CeWorkerRunnableImpl.executeTask(CeWorkerRunnableImpl.java:78) [sonar-server-5.2.jar:na]
at org.sonar.server.computation.taskprocessor.CeWorkerRunnableImpl.run(CeWorkerRunnableImpl.java:55) [sonar-server-5.2.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_45-internal]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_45-internal]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_45-internal]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_45-internal]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45-internal]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45-internal]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45-internal]
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.PacketTooBigException:     Packet for query is too large (7989143 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.
### The error may involve org.sonar.db.source.FileSourceMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO file_sources (project_uuid, file_uuid, created_at, updated_at, binary_data, line_hashes, data_hash,     src_hash, data_type, revision)     VALUES (?, ?, ?,     ?, ?, ?,     ?, ?,?,     ?)
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (7989143 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:154) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.2.7.jar:3.2.7]
at com.sun.proxy.$Proxy84.insert(Unknown Source) ~[na:na]
at org.sonar.db.source.FileSourceDao.insert(FileSourceDao.java:117) ~[sonar-db-5.2.jar:na]
at org.sonar.server.computation.step.PersistFileSourcesStep$FileSourceVisitor.persistSource(PersistFileSourcesStep.java:160) ~[sonar-server-5.2.jar:na]
at org.sonar.server.computation.step.PersistFileSourcesStep$FileSourceVisitor.visitFile(PersistFileSourcesStep.java:130) ~[sonar-server-5.2.jar:na]
... 18 common frames omitted
Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (7989143 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3540) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2417) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1203) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:50) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152) ~[mybatis-3.2.7.jar:3.2.7]
... 25 common frames omitted

所以现在我已经将Shell脚本代码覆盖率生成行更新为

So now I've updated the shell script code coverage generation line to

node_modules/.bin/istanbul cover -x node_modules ./node_modules/.bin/_mocha path-to-unit-tests

仍然得到异常.基于 max_allowed_pa​​cket,我没有MySQL ,我需要在数据库设置中增加MAX_ALLOWED_PACKET的值.刚完成此操作,然后重新触发了詹金斯的工作以进行SonarQube分析.异常消失了. SonarQube中的后台任务已成功完成.但是我仍然没有在仪表板上看到单元测试代码的覆盖范围.没有其他例外.当我单击配置小部件"按钮时,单元测试小部件上有无数据"标签.当我回到仪表板时,单元测试"小部件消失了.

Still getting the exception. Based on max_allowed_packet, I don't have MySQL, I need to bump up the value of MAX_ALLOWED_PACKET in the database settings. Just done that and retriggered the Jenkins job for SonarQube analysis. The exception disappeared. The background task in SonarQube was successful. But I still don't see Unit test code coverage in the dashboard. There are no other exceptions. When I click on 'Configure Widgets' button, the Unit test widget has 'No data' label on it. When I go back to the dashboard, the Unit test widget disappears.

知道我想念什么吗?

推荐答案

在我修复了问题中提到的异常之后,lcov报告发布工作正常了.但是有时候,我会随机看到另一个例外.此外,SonarQube仪表板上的单元测试"小部件仅显示条件"覆盖率.需要进一步调整解决方案.

The lcov report publishing worked after I had fixed the exception mentioned in the question. But sometimes, I randomly see another exception. Moreover, the Unit test widget on the SonarQube dashboard shows only the Conditionals coverage. Need to fine tune the solution more.

sonar.dynamicAnalysis=reuseReports
sonar.javascript.lcov.reportPath=project-name/coverage/lcov.info

这篇关于SonarQube分析未显示代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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