Code coverage is not sent to SonarQube

Hello, I’m facing with an issue that my coverage data is not being sent to SonarQube.
Build is executed on azure devops windows-latest agent.

- task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@5
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: SonarQube
    projectKey: '$(Sonar.ProjectKey)'
    projectName: '$(Sonar.ProjectName)'
    projectVersion: '$(Sonar.ProjectVersion)'
    extraProperties: |
     sonar.exclusions=**/obj/**,**/*.dll
     sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
     sonar.verbose=true

- task: DotNetCoreCLI@2
  displayName: 'build - restore packages'
  inputs:
    command: restore
    projects: '$(Backend.SolutionPath)'
    vstsFeed: '<feed>'
    noCache: true

- task: DotNetCoreCLI@2
  displayName: 'build - build solution'
  inputs:
    projects: '$(Backend.SolutionPath)'
    arguments: '-c Release'

- task: DotNetCoreCLI@2
  displayName: 'test - run unit tests'
  inputs:
    command: test
    projects: '$(Backend.SolutionPath)'
    arguments: '--configuration Release -v n --settings $(Build.SourcesDirectory)/$(Coverage.SettingsFilePath) --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover'
    publishTestResults: false

- task: SonarSource.sonarqube.6D01813A-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@5
  displayName: 'Run Code Analysis'

- task: SonarSource.sonarqube.291ed61f-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@5
  displayName: 'Publish Quality Gate Result'

In the logs i can see that coverage reports files were correctly located:

16:11:09.454 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'C:\agent\_work\2\.' and file separator '\'.
16:11:09.454 DEBUG: Pattern matcher extracted prefix/absolute path 'C:\agent\_work\2\s' from the given pattern 'C:\agent\_work\2\s/**/coverage.opencover.xml'.
16:11:09.455 DEBUG: Gathering files for wildcardPattern '**\coverage.opencover.xml'.
16:11:10.034 DEBUG: Pattern matcher returns '17' files.
16:11:10.034 DEBUG: The current user dir is 'C:\agent\_work\2'.
16:11:10.034 INFO: Parsing the OpenCover report C:\agent\_work\2\s\aspnet-core\test\<project-name>\TestResults\0356f0d1-9422-4b8a-b591-8b6afdb02425\coverage.opencover.xml

I suspect the issue is the following error:

16:11:10.058 DEBUG: Skipping the import of OpenCover code coverage for the invalid file path: https://dev.azure.com/<org>/<project>/_apis/git/repositories/<proj-name>/items?api-version=1.0&versionType=commit&version=<commit-hash>&path=/aspnet-core/src/<proj-name>/Consts.cs at line 10
java.io.IOException: Bad pathname
	at java.base/java.io.WinNTFileSystem.canonicalize0(Native Method)
	at java.base/java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:496)
	at java.base/java.io.File.getCanonicalPath(File.java:626)
	at org.sonar.plugins.dotnet.tests.OpenCoverReportParser$Parser.handleFileTag(OpenCoverReportParser.java:97)
	at org.sonar.plugins.dotnet.tests.OpenCoverReportParser$Parser.dispatchTags(OpenCoverReportParser.java:76)
	at org.sonar.plugins.dotnet.tests.OpenCoverReportParser$Parser.parse(OpenCoverReportParser.java:66)
	at org.sonar.plugins.dotnet.tests.OpenCoverReportParser.accept(OpenCoverReportParser.java:43)
	at org.sonar.plugins.dotnet.tests.OpenCoverReportParser.accept(OpenCoverReportParser.java:30)
	at org.sonar.plugins.dotnet.tests.CoverageCache.readCoverageFromCacheOrParse(CoverageCache.java:39)
	at org.sonar.plugins.dotnet.tests.CoverageAggregator.mergeParsedCoverageWithAggregatedCoverage(CoverageAggregator.java:142)
	at org.sonar.plugins.dotnet.tests.CoverageAggregator.aggregate(CoverageAggregator.java:133)
	at org.sonar.plugins.dotnet.tests.CoverageAggregator.aggregate(CoverageAggregator.java:112)
	at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyze(CoverageReportImportSensor.java:92)
	at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.execute(CoverageReportImportSensor.java:84)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ProjectSensorsExecutor.execute(ProjectSensorsExecutor.java:52)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:371)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)

I get this error for all report files.
I guess i should have here local absolute path to the sources? How can i achieve that?

This is the example of coverage file

Unfortunately i was not able to find any similar issue.
Appreciate any help!

Hi,

Welcome to the community!

I think you’ve correctly diagnosed the problem

Unfortunately, how to get OpenCover to generate a report with relative paths is a bit out of scope for us. I can only point you to the example in the docs.

 
Ann

Thank you so much for your response!
I figured it’s because i had property UseSourceLink set to true in my runsettings file.
After i changed it to false - it fixed the path in report and coverage data is correctly pushed to Sonar.

I think i will alter my runsettings file to have two data collectors - one for sonar with UseSourceLink set to false and opencover format and one more for cobertura and UseSourceLink set to true to report coverage data into Azure DevOps build pipeline.

Thank you again!

1 Like