Bamboo + sonar.dynamicAnalysis=reuseReports = 0% Rules Compliance

橙三吉。 提交于 2019-12-21 20:08:12

问题


Bamboo is in place to do continuous builds, but want to use Sonar for quality metrics tracking. Unit test pass/fail and Clover code coverage metrics must be captured in Bamboo. But, these same values should be sent to Sonar as well, so as to not increase build duration by running unit tests and Clover twice.

Have been able to send these metrics from Bamboo builds to Sonar using "sonar.dynamicAnalysis=reuseReports" directive with the maven build. But the "Rules Compliance" metric in Sonar goes to 0%.

Based on prior tinkering without using the directive the Rules Compliance score is higher. So it's clear using the directive is somehow preventing that metric from being calculated.

Does anyone know how to use this directive and get a Rules Compliance score? Or can they point out something to look at to help diagnose? Running maven with the "-e" option has not provided anything particularly useful.


回答1:


After much trail and error, I finally was able to get Sonar, Jacoco, and Bamboo working harmoniously together. I documented the process here!, but I'll copy my solution here to ensure it's always available.

For my application, I actually used a sonar runner tasks. You have more explicit steps to install and configure the sonar-runner, which isn't mentioned in the install guide. First, you must install the sonar-runner and specify the following properties in your sonar-runner.properties:

#----- Default Sonar server
sonar.host.url=http://localhost:9000

#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#sonar.jdbc.driver=org.postgresql.Driver

#----- Global database settings
sonar.jdbc.username=user
sonar.jdbc.password=passwd

Include the jacoco xmlns in your ant build script at the top:

<project basedir="." default="build" name="project" xmlns:jacoco="antlib:org.jacoco.ant">
    <property environment="env" />

    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
       <classpath path="libs/independent/jacocoant.jar"/>
    </taskdef>

Next, you have to add jacoco coverage to your ant build script:

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

Last, you need to tell sonar, from bamboo, to use jacoco results and reuse the reports generated in your build. You do this by adding the following properties to your "Custom Extra Parameters" in the Task configure for sonar analysis in the Bamboo Job. Configure the following options:

-DbuildNumber=${bamboo.buildNumber}
-Dsonar.core.codeCoveragePlugin=jacoco
-Dsonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.surefire.reportsPath=tests/test-reports

Once I had all this configured, my test coverage started showing up in sonar with the # successful tests listed.

Just be sure you set the sunfire property to reuse their reports generated from your unit tests. Otherwise, sonar won't know where to find them even if you tell it to reuse reports. Hope that helps at your next attempt.




回答2:


Please go to the following

Link and Link 2



来源:https://stackoverflow.com/questions/8081246/bamboo-sonar-dynamicanalysis-reusereports-0-rules-compliance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!