Project sometimes shows code coverage and other times it reverts to 0%

We have a Java project with 2 separate builds in Jenkins.

One of the builds runs integration tests, and generates code coverate (JaCoCo), which we feed into sonarscanner. When this build runs and succeeds, we see code coverage in SonarCloud showing up. This build is executed via the following:
mvn sonar:sonar -Dsonar.branch.name='$BRANCH' -Dsonar.coverage.jacoco.xmlReportPaths=target/jacoco-tests/jacoco.xml --batch-mode

The second build only runs the sonar analysis (without the integration tests), and thus no code coverage data is available. We completely omit the coverage related parameters from sonarscanner. When this build runs, the code coverage in SonarCloud gets reset to 0%.
This build is executed via the following:
sonar-scanner -Dproject.settings=./sonar-project.properties -Dsonar.branch.name="$BRANCH"

Is this expected behavior?
Any help / guidance would be greatly appreciated.

Hi Anthony,

Welcome to the SonarSource Community!

SonarCloud expects that coverage information is supplied for each analysis, else it will report no coverage.

I’m assuming that each of these builds is of the same code in the same state. In this case you should only run the scan at the time of the build that runs the scan(s).

Cheers

Brian

Hi Brian,

In our case, generating the code coverage takes a long time due to integration tests, and so we split the analysis into a smaller job (without coverage) and a larger job (with coverage).

I’ll see about retooling my setup. I appreciate the clarification.

Cheers,
Anthony

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.