Sonar Code coverage at 0% after upgrade to 8.3

Must-share information (formatted with Markdown):

  • Version: Sonarqube 8.3
  • Code Coverage is showing at 0% in test environment after upgrade to 8.3

We recently upgraded our test environment to v8.3 and now the projects are not showing code coverage after analysis. Production is showing correct Code coverage on v7.9.1 for the same project. The test environment was recently restored with prod data so the projects are functionally identical.

We are using the sonar-jacoco plugin and I have tried specifying the xml report path using wildcards and explicitly but it’s still not working.

I can confirm that the “jacoco.xml” file DOES exist at that path.

Thanks in advance for any assistance.
Devon.

So I got this working if I specify an explicit path in the build arguments in Azure DevOps. We have multiple build servers and agents so this is not ideal.

Is there some sort of guide on using the wildcards for the path? I’ve tried “***.xml” but it doesn’t work.

Hi,

Try Ant patterns: ** for 0-n directories, and * for 0-n characters. E.G: **/jaco*.xml

 
HTH,
Ann

Thanks for the reply.

Not sure how I missed my spelling error in my original post but I have already tried “**/jacoco.xml” not “***jacoco.xml” ~facepalm~

Hi,

Can you give an example working and non-working path? I’m wondering if this is about OSes and slashes (’/’ vs ‘’).

 
Ann

Hi Ann.

Sure thing…

The working path is “/data/AzureDevOpsAgents/A1/_work/57/s/CCReport43F6D5EF/jacoco.xml” and any variation of **/jacoco.xml or **/*.xml etc aren’t working.

I’ve also tried both of these in the build arguments in TFS as well as in the settings in Sonarqube and I get the same results. The wildcard approach isn’t working either way.
Kind Regards,
Devon.

Hi Devon,

There should be something in the analysis logs about the attempt to read those reports…?

 
Ann

Hi Ann.

The build logs show the following…

WRT the Analysis logs, where are those? I’ve checked the ce.log file in the logs folder but I don’t see anything about the XMLReport path and I found the following in the access.log file…Are there any other logs that I need to check?

Kind Regards,
Devon Britton.

Hi Devon,

Build logs == analysis logs. And I’m reminded now that you provided that snippet in your original post. Sorry about that.

So… The reports exist at CCReport*/jacoco.xml. But analysis is looking for them under target. That implies to me that you’re doing a Maven analysis…? But not… generating the coverage reports via Maven?

Anyway, this looks like a bug in how those paths are read - unless the context for ** isn’t what you think it is. Could you provide - as text (purple on black at that font size is hard on the eyes!) - the analysis subset of your build log? Also, it might be helpful to add sonr.scanner.dumpToFile=[file name] to your analysis command line one time to see exactly what interpolated properties analysis is getting.

 
Ann

Hi Devon,

I’m confused by this log. There seem to be multiple Maven commands, all of them with analysis parameters, but only one that invokes the analysis task(?), and that with -Dsonar.jacoco.reportPaths=/data/AzureDevOpsAgents/A1/_work/57/s/CCReport43F6D5EF/jacoco.exec. I’m also confused about why the reports aren’t being dumped into the default location (as I implied earlier).

Anyway, I see analysis start to look for **/jacoco.xml on line 19205(!) and I see jacoco.xml actually generated(?) on line 20040.

Since you’re running this job as an upgrade test (-Dsonar.projectKey=com.electrabel.channels.web:bll-alerting:platformUpgradeTest) I suggest you turn off debug logging and whittle the job back to the bare minimum: clean, build, run tests & generate reports, analyze. Then it will be more apparent what’s actually going on.

 
Ann

Thanks for the insight and suggestion Ann.

I assume the fact that this is a multimodule project would account for the multiple maven commands?

The build pipeline only contains 2 steps, “Prepare Analysis on Sonarqube” and the “Maven pom.xml” build step so I’m not actually sure where the reports are being generated and how they’re being dumped to their location (this isn’t my project, I’m just assisting with the Sonar issue) or how I can whittle down the job any further.

I’ll have to try get the project dev on the line when he gets back from holiday next week.

Hi @ganncamp

I still haven’t had any luck sorting this issue. I’m not able to track down where the extra Maven commands are coming from. I see there are 3 in total but I’vew checked the pom.xml files for all of the associated modules and there’s nothing there. Is it at all possible that the Azure DevOps build step for “Prepare Analysis on Sonarqube” could be inserting extra config into the build somehow? I very much doubt it but I’m at my wits end right now.

Kind Regards,
Devon Britton.

Just to continue along this train of thought… regardless of what configuration I put in the pom.xml file, I find the following in the pom.xml on the build server after the build is complete. My config is still there as well, but this is added somewhere along the line during the build and I can’t figure out where or how.

<build>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.4</version>
        <configuration>
          <destFile>/data/AzureDevOpsAgents/A1/_work/57/s/CCReport43F6D5EF/jacoco.exec</destFile>
          <outputDirectory>/data/AzureDevOpsAgents/A1/_work/57/s/CCReport43F6D5EF</outputDirectory>
          <dataFile>/data/AzureDevOpsAgents/A1/_work/57/s/CCReport43F6D5EF/jacoco.exec</dataFile>
          <append>true</append>
          <includes>
            <include>**/com/*/**</include>
          </includes>
          <excludes>
            <exclude>**/*/resources/*/**</exclude>
            <exclude>**/*model/*/**</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <configuration>
              <includes>
                <include>**/*</include>
              </includes>
            </configuration>
            <id>default-prepare-agent-vsts</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>default-report-vsts</id>
            <goals>
              <goal>report</goal>
            </goals>
            <phase>test</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

I have searched all the pom.xml files of all the modules in the project and that particular config is nowhere to be found which is why I think it might be part of the build step.

Kind Regards,
Devon Britton.

Hi @DevonBritton

Which version of the Maven task is displayed when you are executing your build ?
Where also do you set the path to the jacoco report ? In the UI ? Or as a parameter in your Prepare analysis configuration task ?

Thanks.

Hi @mickaelcaro.

The Maven task is 3.* . I’ve tried with 2.* as well but I get warnings in the build and no code coverage data is found at all.

I’ve tried specifying the path in both places you mention. It works if I specify the full path but not if I try use wildcards.

Kind Regards,
Devon Britton.

Thanks. Let’s try to stick into one single place (either the UI or the task configuration).

It should be better as well to at least specify a root path using one of the availble variable from the Build Pipeline, let’s say for example $(Agent.TempDirectory)/**/jacoco.xml something like this. Can you try that ?

Thanks @mickaelcaro.

The following works in the build options,

-Dsonar.coverage.jacoco.xmlReportPaths="$(System.DefaultWorkingDirectory)/**/jacoco.xml"

but “$(System.DefaultWorkingDirectory)/**/jacoco.xml” does not work in the Sonar UI. Do those types of variables work in the Sonar UI?

This is a slightly better workaround than I had previously but we would still have to update dozens of builds with this and it would obviously be preferable to set it once in Sonar and then it’s done.

Kind Regards,
Devon Britton.

On another note @mickaelcaro, it seems like this fix only works on one of the projects. I’m trying the same strategy on another project with the missing code coverage issue and it’s not working. As you can see from the below logs, both builds read the code coverage successfully from the xml file located at “$(System.DefaultWorkingDirectory)/**/jacoco.xml” but the project on the left has code coverage in Sonar but the project on the right does not…

I have also checked both jacoco.xml files and they both contain valid (to my knowledge) data.

Kind Regards,
Devon Britton.

Just adding to this @mickaelcaro and @ganncamp

We’ve moved back to v 7.9.3 to see if the issue would be resolved by going back to the latest LTS version but we’re having the same issue. It’s important to note that our production environment is on 7.9.1 and is not having these issues.

Kind Regards,
Devon Britton.

Hi @DevonBritton

The screenshot you mentionned speaks about uploading coverage to TFS Server, not SonarQube.

Could you please send me the log in debug mode of the Maven task ? It would also be ideal to have both the one working and the one that is not.

I can PM you if you need to send it privately.

Thanks.