Search code examples
sonarqubecode-coveragesonarqube-scanopencover

Code coverage results not getting updated with Branching in sonarqube


I am working on integrating sonarqube in Jenkins pipeline. I have enabled code coverage on sonarqube with opencover using sonar-csharp as per the documentation below https://docs.sonarqube.org/pages/viewpage.action?pageId=6389770 I am also using the branch plugin. When i start the sonarqube analysis command with /d:sonar.branch.name and /d:sonar.branch.target , the coverage results on the master branch stays at 0% and the coverage results on the specific branch remains blank. When i remove the /d:sonar.branch.name and /d:sonar.branch.target, the coverage results on the master gets updated to a specific value, but the coverage results on the specific branch in the code tab is still blank. Shouldn't the code coverage percentages be updated accordingly in the specific branch and why do i see this difference in behaviour with the use of branch plugin. Please let me know if i am missing something. Below are the versions of the tools i am using

SonarQube Server 6.7.2 Sonar-C# 6.8.2.4717 Opencover - 4.6.519

I have tested the behavior with both opencover and visual studio coverage. I have tried to check if there are any errors by enabling the verbose logging during the sonarqube analysis and i do see that the coverage report is imported and analyzed by sonarqube, but the results are not displayed in the web page. Below is what i see in both successful and failure scenarios

INFO: Sensor C# Tests Coverage Report Import [csharp] INFO: Parsing the OpenCover report C:\agent\workspace\xxxx\xxxx\opencovertests.xml INFO: Adding this code coverage report to the cache for later reuse: C:\agent\workspace\xxxxx\xxxx\opencovertests.xml INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=183ms INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=95ms Analysis report generated in C:\agent\workspace\xxxx\xxxx.sonarqube\out.sonar\scanner-report Analysis report uploaded in 873ms INFO: ANALYSIS SUCCESSFUL

Blank Coverage

Regards, Chiranth


Solution

  • What is the name of your branch? If this name is NOT matching the regular expression corresponding to Long-Lived branches (sonar.branch.longLivedBranches.regex), then it's normal to not see the coverage data. As of now, it's only possible to feed coverage data in SonarQube on the Master and Long-Live branches, not on short-lived branches.

    Regards