5

I am trying to upload Unit Test and dotCover Code Analysis results from TeamCity to Sonar server. It shows code coverage and unit test results in the TeamCity but no code coverage/unit test on Sonar.

enter image description here

TeamCity Unit test step:

enter image description here

Followed by Powershell script:

enter image description here

I have the following additional parameter in Sonar Runner step:

Dsonar.cs.vstest.reportsPaths=TestResults.trc Dsonar.cs.dotcover.reportsPaths='%sonar.coverageReport%'

Does anyone know how to fix this?

Thanks.

developer
  • 1,401
  • 4
  • 28
  • 73
  • I had this same problem importing dotCover results. I worked around the problem by using OpenCover results instead (which seem to import fine). That doesn't help you much, but does indicate that the problem relates to dotCover results in particular. – ScheuNZ Dec 22 '15 at 05:14
  • FYI: The SonarQube Scanner for MSBuild should be used instead of the sonar-runner to analyze MSBuild projects. The use of the sonar-runner is deprecated. – Dinesh Bolkensteyn Dec 22 '15 at 08:48
  • Can you add the logs with `sonar.verbose=true`? What does it say when it tries to import the dotcover report? – Dinesh Bolkensteyn Dec 22 '15 at 08:48

2 Answers2

4

Managed to fix the issue using the below script in step 3:

$Files= Get-ChildItem %system.teamcity.build.tempDir% ` 
    -Filter coverage_dotcover*.data ` 
    | where-object {$_.length -gt 50} ` 
    | Select-Object -ExpandProperty FullName 

$snapshot =[string]::Join(";",$Files) 

& %teamcity.tool.dotCover%\dotCover.exe merge ` 
  /Source=$snapshot ` 
  /Output=%env.TEMP%\dotCoverReport.dcvr` 


& %teamcity.tool.dotCover%\dotCover.exe report ` 
  /Source=%env.TEMP%\dotCoverReport.dcvr ` 
  /Output=%sonar.coverageReport% ` 
  /ReportType=HTML
harishr
  • 17,807
  • 9
  • 78
  • 125
developer
  • 1,401
  • 4
  • 28
  • 73
2

What TeamCity version do you have? In TeamCity 9.1.1 there was a bug that caused test report files to be written in build temp directory. In this case Sonar plugin, that expects trx file to be in checkout directory, does not find it. There are several ways to solve it: the first is to upgrade to TeamCity 9.1.2 and above, the second is to pass absolute path to the report paths variable:

-Dsonar.cs.vstest.reportsPaths=%system.teamcity.build.tempDir%/TestResults.trc

The third way would be to pass absolute path, that points to checkout directory, to results file field of mstest runner:

%system.teamcity.build.checkoutDir%/TestResults.trc

Oleg Rybak
  • 1,651
  • 1
  • 14
  • 27
  • Thanks for your answer. I have a similar problem Im using your lines and Its possible to get only C# coverage. In my code I have mix of vb.net and C#. Do you know what is the config for that case ? Thanks! – CABascourt Sep 12 '19 at 15:35