SonarCloud results not pushed

Issue

We’re doing an Incremental PR analysis using SonarCloud in Azure DevOps pipeline but the code coverage and duplications results are not pushed anymore. The rest of the metrics are coming through normally.

In the SonarCloud portal we’re either seeing 0% coverage or a message telling us to set up code coverage.

We have validated that no relevant changes have been made to the code, pipeline, infrastructure or SonarCloud settings.

We are using the default Azure Devops SonarCloud task for all three steps with the default settings besides three file exclusion rules. Removing these rules entirely didn’t seem to fix the issue.

We are seeing coverage in the associated DevOps pipeline:
image

Any help on this would be greatly appreciated.

Yaml pipeline steps

Below are the used pipeline steps.

Prepare sonarcloud

parameters:
- name: projectKey
  type: string

### Prepare SonarCloud
steps:
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
  displayName: 'Prepare analysis on SonarCloud'
  inputs:
    SonarCloud: SonarCloud
    organization: ##Redacted##
    projectKey: ${{ parameters.projectKey }}

Run SonarCloud Analysis

# Run SonarCloud Analysis
steps:
- task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
  displayName: 'Run SonarCloud Analysis'

Publish SonarCloud results

# Publish Quality Gate Result
steps:
- task: SonarSource.sonarcloud.38b27399-a642-40af-bb7d-9971f69712e8.SonarCloudPublish@1
  displayName: 'Publish Quality Gate Result'

Logs

Prepare SonarCloud logs:

SonarScanner for MSBuild 5.13
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
08:37:50.931 Updating build integration targets...
08:37:51.102 Fetching analysis configuration settings...
08:37:51.743 Provisioning analyzer assemblies for cs...
08:37:51.743 Installing required Roslyn analyzers...
08:37:51.743 Processing plugin: csharp version 9.3.0.71466
08:37:52.025 Processing plugin: vbnet version 9.3.0.71466
08:37:52.087 Processing plugin: securitycsharpfrontend version 10.1.0.21056
08:37:52.4 Provisioning analyzer assemblies for vbnet...
08:37:52.4 Installing required Roslyn analyzers...
08:37:52.4 Processing plugin: csharp version 9.3.0.71466
08:37:52.4 Processing plugin: vbnet version 9.3.0.71466
08:37:52.4 Incremental PR analysis: Base branch parameter was not provided.
08:37:52.415 Cache data is empty. A full analysis will be performed.
08:37:52.431 Pre-processing succeeded.
Finishing: Prepare analysis on SonarCloud

Run SonarCloud Analysis logs:

SonarCloudLogs.txt (126.9 KB)

Publish SonarCloud results logs

Starting: Publish Quality Gate Result
==============================================================================
Task         : Publish Quality Gate Result
Description  : Publish SonarCloud's Quality Gate result on the Azure Pipelines build result. To be used after the actual analysis.
Version      : 1.12.0
Author       : sonarsource
Help         : Version: 1.12.0. [More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
==============================================================================
Finishing: Publish Quality Gate Result

Based on the logs…

2023-06-13T20:22:49.4191369Z INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\1c00fcfe-83c7-4067-884e-5f9c6a6e8308\VssAdministrator_fv-az625-697_2023-06-13.20_19_32.coveragexml
2023-06-13T20:22:52.6752587Z INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\1c00fcfe-83c7-4067-884e-5f9c6a6e8308\VssAdministrator_fv-az625-697_2023-06-13.20_19_32.coveragexml
2023-06-13T20:22:52.7109370Z INFO: Coverage Report Statistics: 398 files, 0 main files, 0 main files with coverage, 398 test files, 0 project excluded files, 0 other language files.
2023-06-13T20:22:52.7111165Z WARN: The Code Coverage report doesn't contain any coverage data for the included files. Troubleshooting guide: https://community.sonarsource.com/t/37151
2023-06-13T20:22:52.7114089Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=3308ms

It looks like a coverage report is found, but none of the files inside have been identified as source files (but rather test files).

Elsewhere in your logs it looks like you might have a few projects being identified as test projects that shouldn’t be (based on project names and file paths)

2023-06-13T20:22:34.7231457Z INFO: Indexing files of module '##REDACTED##.Usages.BusinessLogic.Usages'
2023-06-13T20:22:34.7231881Z INFO:   Base dir: D:\a\1\s\code\##REDACTED##.Usages.DomainServices
2023-06-13T20:22:34.7232637Z INFO:   Test paths: UsagesServiceRegistrations.cs, UsagesV3Belgie/GetUsagesBelgieDt...
2023-06-13T20:22:34.7233250Z INFO:   Excluded sources: **/build-wrapper-dump.json, code/##REDACTED##.*.Api/**, code/##REDACTED##.*.Repositories/**, code/##REDACTED##.*.Client/**
2023-06-13T20:22:34.7233772Z INFO:   Excluded sources for coverage: code/##REDACTED##.Usages.Api/**, code/##REDACTED##.Usages.Repositories/**, code/##REDACTED##.Usages.Client/**
....
2023-06-13T20:22:34.7254043Z INFO: Indexing files of module '##REDACTED##.Usages.Api'
2023-06-13T20:22:34.7254402Z INFO:   Base dir: D:\a\1\s\code\##REDACTED##.Usages.Api
2023-06-13T20:22:34.7254826Z INFO:   Test paths: Controllers/DeviceScheduleController.cs, Controllers/EnergyRada...
2023-06-13T20:22:34.7255396Z INFO:   Excluded sources: **/build-wrapper-dump.json, code/##REDACTED##.*.Api/**, code/##REDACTED##.*.Repositories/**, code/##REDACTED##.*.Client/**
2023-06-13T20:22:34.7255859Z INFO:   Excluded sources for coverage: code/##REDACTED##.Usages.Api/**, code/##REDACTED##.Usages.Repositories/**, code/##REDACTED##.Usages.Client/**
....
2023-06-13T20:22:34.7268878Z INFO: Indexing files of module '##REDACTED##.Usages.BusinessLogic'
2023-06-13T20:22:34.7269266Z INFO:   Base dir: D:\a\1\s\code\##REDACTED##.Usages.BusinessLogic
2023-06-13T20:22:34.7269674Z INFO:   Test paths: BillBreakdownService.cs, Builders/ApigeeWeatherDayWeekMonthVari...
2023-06-13T20:22:34.7270329Z INFO:   Excluded sources: **/build-wrapper-dump.json, code/##REDACTED##.*.Api/**, code/##REDACTED##.*.Repositories/**, code/##REDACTED##.*.Client/**
2023-06-13T20:22:34.7270791Z INFO:   Excluded sources for coverage: code/##REDACTED##.Usages.Api/**, code/##REDACTED##.Usages.Repositories/**, code/##REDACTED##.Usages.Client/**

Notice how these projects identify Test paths. Are these projects that normally there would be code coverage reported on? It would be good to compare previous runs to see if this was the same when coverage was being reported to SonarCloud correctly.

I would also suggest looking at this documentation on the Analysis of product projects vs. test projects. This can be influenced by things like certain dependencies (like xunit) being added to your sub-projects, which means there might still be something that changed which you weren’t aware of.

Hey Colin,

Thanks for the reply.
You are correct. There where some leftover settings from testing that caused this.

But after removing these settings, they’re still identified as tests.
Will try to set the inclusion parameters for test paths to see if that helps.

Setting the test filepath inclusion seems to work. Files are now properly recognized as source files.

But as of right now, SCM is not being able to pick up the changes. It looks like the coverage results are not being parsed correctly from the XML report.

We’re seeing a lot of debug warning of files not being included for coverage:

2023-06-19T07:23:38.4057234Z 07:23:38.389 INFO: Found 20 MSBuild C# projects: 2 MAIN projects. 18 with no MAIN nor TEST files.
2023-06-19T07:23:38.4057516Z 07:23:38.389 INFO: Sensor C# [csharp] (done) | time=687ms
2023-06-19T07:23:38.4057783Z 07:23:38.389 INFO: Sensor Analysis Warnings import [csharp]
2023-06-19T07:23:38.4058345Z 07:23:38.389 INFO: Sensor Analysis Warnings import [csharp] (done) | time=0ms
2023-06-19T07:23:38.4058625Z 07:23:38.389 INFO: Sensor C# File Caching Sensor [csharp]
2023-06-19T07:23:38.4059196Z 07:23:38.389 INFO: Sensor C# File Caching Sensor [csharp] (done) | time=0ms
2023-06-19T07:23:38.4059478Z 07:23:38.389 INFO: Sensor C# Tests Coverage Report Import [csharp]
2023-06-19T07:23:38.4060002Z 07:23:38.389 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'D:\a\1\.' and file separator '\'.
2023-06-19T07:23:38.4060502Z 07:23:38.389 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\_temp' from the given pattern 'D:\a\_temp\**\*.coveragexml'.
2023-06-19T07:23:38.4498021Z 07:23:38.421 DEBUG: Gathering files for wildcardPattern '**\*.coveragexml'.
2023-06-19T07:23:38.4512450Z 07:23:38.421 DEBUG: Pattern matcher returns '1' files.
2023-06-19T07:23:38.4513500Z 07:23:38.421 DEBUG: The current user dir is 'D:\a\1'.
2023-06-19T07:23:38.4514188Z 07:23:38.421 INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\2820b568-5dfb-4543-baa8-3802b134eb34\VssAdministrator_fv-az285-31_2023-06-19.07_19_05.coveragexml
2023-06-19T07:23:38.9448299Z 07:23:38.749 DEBUG: Did not find deterministic source path in 'D:\a\1\s\code\DC.Usages.##REDACTED##.cs'. Will skip this coverage entry.
2023-06-19T07:23:39.0451883Z 07:23:38.905 DEBUG: Did not find deterministic source path in 'D:\a\1\s\code\DC.Usages.##REDACTED##.cs'. Will skip this coverage entry.

Further down the logs. SCM not picking up changes:

2023-06-19T07:23:40.0749272Z 07:23:39.781 DEBUG: Analyzing coverage after aggregate found '50' coverage files.
2023-06-19T07:23:40.0749663Z 07:23:39.781 DEBUG: The total number of file count statistics is '50'.
2023-06-19T07:23:40.0750050Z 07:23:39.797 INFO: Coverage Report Statistics: 50 files, 50 main files, 50 main files with coverage, 0 test files, 0 project excluded files, 0 other language files.
2023-06-19T07:23:40.0750420Z 07:23:39.797 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=1408ms
2023-06-19T07:23:40.0750697Z 07:23:39.797 INFO: Sensor C# Unit Test Results Import [csharp]
2023-06-19T07:23:40.0751158Z 07:23:39.797 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\_temp' from the given pattern 'D:\a\_temp\**\*.trx'.
2023-06-19T07:23:40.0751578Z 07:23:39.797 DEBUG: Gathering files for wildcardPattern '**\*.trx'.
2023-06-19T07:23:40.0751942Z 07:23:39.797 DEBUG: Pattern matcher returns '1' files.
2023-06-19T07:23:40.0752276Z 07:23:39.797 DEBUG: The current user dir is 'D:\a\1'.
2023-06-19T07:23:40.0752742Z 07:23:39.797 INFO: Parsing the Visual Studio Test Results file 'D:\a\_temp\VssAdministrator_fv-az285-31_2023-06-19_07_22_03.trx'.
2023-06-19T07:23:40.0753201Z 07:23:39.797 DEBUG: Parsed Visual Studio Test Times - duration: 191932.
2023-06-19T07:23:40.0753658Z 07:23:39.828 DEBUG: Parsed Visual Studio Test Counters - total: 756, failed: 0, errors: 0, timeout: 0, aborted: 0, executed: 756.
2023-06-19T07:23:40.0754001Z 07:23:39.843 INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=46ms
2023-06-19T07:23:40.0754279Z 07:23:39.843 INFO: Sensor Zero Coverage Sensor
2023-06-19T07:23:40.0754530Z 07:23:39.843 INFO: Sensor Zero Coverage Sensor (done) | time=0ms
2023-06-19T07:23:40.0754803Z 07:23:39.843 INFO: CPD Executor Calculating CPD for 0 files
2023-06-19T07:23:40.0755085Z 07:23:39.843 INFO: CPD Executor CPD calculation finished (done) | time=0ms
2023-06-19T07:23:40.0755342Z 07:23:39.937 INFO: SCM writing changed lines
2023-06-19T07:23:40.0786635Z 07:23:39.953 DEBUG: SCM reported changed lines for 0 files in the branch
2023-06-19T07:23:40.0786919Z 07:23:39.953 INFO: SCM writing changed lines (done) | time=16ms

It sounds like there might be two (seperate) issues here. Let’s focus on them one at a time.

Coverage – do you now see any coverage information after a SonarCloud analysis? Either for a branch overall, or in the context of a pull request (including estimated after merge)?

For this specific code repository we do not see any coverage statistics at all.

But the same pipeline scripts are used for all our code repositories and half of those still have coverage stats. I’ve also checked the SonarCloud settings for all the projects, but they’re the same.

Hey Colin,

Did you have time to ?
Can you maybe also tell me what you think the other issue might be, so I can look into that?

Thanks.

did this issue got solved?
I’m reading more issues like this online and wouldn’t know where to start.

Tnx!

How would you start a correct analysis for this problem?

So some time has passed, but the issue still persists.

We tried creating a whole new setup (new repo, builds, releases and sonarcloud projects) following this guide: SonarCube showing 0.00% code coverage with the exact same pipeline steps. This seems to work correctly out of the box so now we can validate all the filepaths and coverage files of this new setup against the old projects.

We’ve setup 3 older projects following the same aforementioned guide:
Our findings are:

  • filepaths used are all identical, both to the old and new setup
  • .trx files are generated well and have the correct test data
  • .coveragexml files are generated well and have the correct coverage data
  • setting up a new sonarcloud project for older projects has no effect.
  • 1 project shows ‘code coverage not Analyzed for SonarCloud’
  • 1 project shows ‘code coverage 0% on SonarCloud’
  • 1 project shows accurate readings

It seems very odd to me that all 3 projects have changed in the same way and use the same pipelines, but still appear to behave differently.

At this point we’ve looked at this issue extensively with 7 engineers and yet we cannot find anything wrong with the setup. We need to find a solution to this or we will be forced to consider alternatives.