Publish coverage reports post msbuild in Jenkins job


I’m looking for a solution for publishing the coverage data for .Net tests that are ran outside the begin-end cycle. This is a Unity project and we have edit time tests and play time tests which run very slowly.
We try to run them in parallel with the sonar scanner process , the problem is that by the time the scanner exits the play tests are not done yet.

Is it possible to achieve this or maybe there is a problem in our solution and there is another way to do parallel analysis?

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarScanner for MSBuild 5.2.1
  • what are you trying to achieve
    I want to run the SonarScanner on a parallel step in a Jenkins Pipeline. The coverage reports will be generated on another parallel stage and need to be integrated in the final SonarQ report. I’m basically looking for a way to send coverage report data to SonarQ after the ‘end’ step.
  • what have you tried so far to achieve this
    Run the same commands w/o building and with the path to the report files in the parameter section
bat "dotnet-sonarscanner begin /key:\"\" /\"\" \
                                    /d:sonar.verbose=true \
                                    /d:sonar.projectBaseDir=\"${sqPath}\" \
                                    /d:sonar.pullrequest.key=${env.gitlabMergeRequestId} \
                                    /d:sonar.pullrequest.branch=${env.gitlabSourceBranch} \
                                    /d:sonar.cs.nunit.reportsPaths=\"%WORKSPACE%\\UnitTests\\EditModeTests\\results.xml,%WORKSPACE%\\UnitTests\\PlayModeTests\\results.xml\" \

                                    bat "dotnet-sonarscanner end"

Thank you for an eventual answer.

Hi @koboldul ,

Welcome to SonarSource Community! :sonarsource:

From our Test Coverage & Execution documentation, note the section about “Improting .NET reports”:

Importing .NET reports

To import .NET reports, the report generation process must be executed after the begin step and before the end MSBuild command. The following steps detail importing .NET reports:

  1. Run the SonarScanner.MSBuild.exe begin command, specifying the absolute path where the reports will be available using the /d:propertyKey="path" syntax (“propertyKey” depends on the tool)
  2. Build your project using MSBuild
  3. Run your test tool, instructing it to produce a report at the same location specified earlier to the MSBuild SonarQube Runner (How to generate reports with different tools)
  4. Run the SonarScanner.MSBuild.exe end command

For more information, see the Generate Reports for C#, Community Post.

Thus, you must run the tests after the BEGIN step and before the END step. If you can run the .NET build and the .NET test report generation in parallel, then that might work, but you still need to make sure the report is complete before you run the END step because the END step requires the entire test report during the scanner analysis.

Hi @Joe

Thank you very much for the quick reply.


1 Like

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