Sonar Cloud Coverage report - Pull request Pipeline

Problem Statement: Inconsistent Code Coverage Reporting Due to Multiple TRX Files in SonarCloud Pull Request Pipeline

Context

We are using SonarCloud to analyze an Azure DevOps pull request pipeline for a .NET project. The pipeline includes multiple test runs,running on different agents, each generating separate .trx files for test results. The SonarCloud analysis runs successfully, but the code coverage is not being reported correctly.

Issue Observed

  1. Multiple .trx files are generated in different test execution steps of the same pipeline.
  2. The SonarCloud “Run Code Analysis” step executes successfully but does not reflect the correct code coverage.
  3. The coverage report is expected to be picked up from the test execution files, but it appears that SonarCloud either does not find the expected coverage files or fails to process them correctly.
  4. The logs do not indicate any direct errors but show that no or partial coverage data is being included in the final report.
  5. The issue does not occur when running the tests locally and generating a single coverage report.

Pipeline Configuration Overview

  • The pipeline executes tests using the dotnet test command.
  • Each test execution creates its own .trx file.
  • SonarCloud is set up using the SonarCloudPrepare, SonarCloudAnalyze, and SonarCloudPublish tasks.
  • The code coverage reports are supposed to be picked up via sonar.cs.vscoveragexml.reportsPaths.

Questions for the Sonar Community

  1. How does SonarCloud handle multiple test result files (.trx) in a single pipeline run?
  2. Should the .trx files be merged before SonarCloud picks up coverage data, or is there an alternative way to configure it?
  3. Is there a recommended way to debug why SonarCloud is not correctly processing the coverage files?

Hi,

Do all the tests run between the begin and end commands in the pipeline?

The tests run on different agents, but presumably you gather them all onto the agent running analysis?

And when you do that, are the file paths in them normalized to match the paths in the analysis workspace?

This guide may help:

 
Ann