Not able to see code coverage on sonar cloud portal

Template for a good new topic, formatted with Markdown:

  • ALM used (Azure DevOps)
  • CI system used (Azure DevOps)
  • Languages of the repository - .NET 8 API
  • Problem
    We have .NET 8 API which has Unit test cases written in Xunit. Deployment is happening using ADO CICD yml pipeline. We have added tasks to generate and show code coverage on Sonar Cloud portal and ADO Pipeline itself. We can see code coverage report in ADO pipeline but Sonar Cloud Portal shows only 0.0% coverage on long lived branch. We are trying to use coverlet for code coverage. Below are yml tasks we are using
- task: SonarCloudPrepare@2
      displayName: "Prepare Sonar Cloud"
      inputs:
        SonarCloud: SonarQubeCloud-CSF          
        organization: $(organization)          
        scannerMode: 'MSBuild'
        ProjectKey: ${{ parameters.sonarProjectKey }}                   
        ProjectName: ${{ parameters.sonarProjectKey }}                                 
        extraProperties: |
          sonar.qualitygate.wait=$(enforceQualityGate)      
          sonar.qualitygate.timeout=300
          sonar.search.customTerms=Dto,Dtos,uri
          sonar.issue.ignore.multicriteria=e1
          sonar.issue.ignore.multicriteria.e1.ruleKey=csharpsquid:S1192
          sonar.issue.ignore.multicriteria.e1.resourceKey=**/Configurations/*.cs
          sonar.cs.coverage.reportPaths=$(Agent.TempDirectory)/**/coverage.cobertura.xml
          sonar.branch.name=$(Build.SourceBranchName)

- script: |
        dotnet restore $(Build.SourcesDirectory)/Services/${{ parameters.serviceName }}/${{ parameters.serviceName }}.sln
        dotnet build $(Build.SourcesDirectory)/Services/${{ parameters.serviceName }}/${{ parameters.serviceName }}.sln -c Release --no-restore
      displayName: Dotnet Restore & Build

- script: |
        echo "Running tests with Cobertura coverage..."
        dotnet test "$(System.DefaultWorkingDirectory)/Services/${{ parameters.serviceName }}/tests/${{ parameters.serviceName }}.UnitTests/${{ parameters.serviceName }}.UnitTests.csproj" \
          --configuration Release \
          --no-build \
          --collect:"XPlat Code Coverage" \
          --results-directory $(Agent.TempDirectory)/coverage \
          --logger trx
      displayName: "Run Tests with Cobertura Coverage"
      continueOnError: true

- task: PublishCodeCoverageResults@1
      displayName: "Publish Cobertura Coverage"
      condition: always()
      inputs:
        codeCoverageTool: 'Cobertura'
        summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml' 
        reportDirectory: '$(Agent.TempDirectory)/**/coverage'
        failIfCoverageEmpty: true

    - task: SonarCloudAnalyze@2
      displayName: "Run SonarCloud Analysis"
      condition: eq('${{ parameters.env }}', 'Dev')

    - task: SonarCloudPublish@2
      displayName: "Publish SonarCloud Results"
      condition: eq('${{ parameters.env }}', 'Dev')
      inputs:
        pollingTimeoutSec: '300'

I feel sonar is not picking up the code coverage file which we generated
Logs

INFO: Sensor C# Analysis Log [csharpenterprise]

INFO: Roslyn version: 4.11.0.0

INFO: Language version: CSharp12

INFO: Concurrent execution: enabled

INFO: Sensor C# Analysis Log [csharpenterprise] (done) | time=13ms

INFO: Sensor C# Method Declarations [csharpenterprise]

INFO: Sensor C# Method Declarations [csharpenterprise] (done) | time=7ms

INFO: Sensor C# Telemetry [csharpenterprise]

INFO: Sensor C# Telemetry [csharpenterprise] (done) | time=3ms

INFO: Sensor C# Telemetry Json [csharpenterprise]

INFO: Sensor C# Telemetry Json [csharpenterprise] (done) | time=2ms

INFO: Sensor C# Properties [csharpenterprise]

INFO: Sensor C# Properties [csharpenterprise] (done) | time=1ms

INFO: Sensor JaCoCo XML Report Importer [jacoco]

INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer

Please help us to show code coverage on portal.

Hi,

Welcome to the community!

Per the docs, that’s not the property to use for a Coverlet report. You want sonar.cs.opencover.reportsPaths=

On the right-hand side of your equals side, I see this:

First, you should make this path relative to your project root. Second, you seem to be passing a Cobertura-formatted report. The docs aren’t super-clear on this point (I’ll be bringing that up internally) but I believe the opencover format is expected.

 
HTH,
Ann