3

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.

orangepips
  • 9,891
  • 6
  • 33
  • 57

2 Answers2

7

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.

Jason Huntley
  • 3,827
  • 2
  • 20
  • 27
  • +1 - thanks for the detailed writeup, much appreciated for tricky integration problems like this one! – Steffen Opel Feb 24 '12 at 09:21
  • Haven't messed with this in awhile, marking as the accepted answer based other people's upvotes and the clear effort put into answering. – orangepips Mar 25 '15 at 14:31
-2

Please go to the following

Link and Link 2

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
Manipal
  • 195
  • 3
  • 7