Test coverage report from a cobertura file generated on Azure pipeline

Hi I have an Azure DevOps pipeline that I can’t seem to get the code coverage into SonarCloud to work at all.

Here is the sections of the yml file that I’ve setup

- task: SonarCloudPrepare@1
        SonarCloud: 'SonarCloud Service Connection'
        organization: 'xx'
        scannerMode: 'MSBuild'
        projectKey: 'xx'
        projectName: 'xx'
        projectVersion: 'sonar.projectVersion'
        extraProperties: |

script: dotnet test Functions/xx/xx.sln /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/
      displayName: Run Unit Tests - $(buildConfiguration)

    - task: DotNetCoreCLI@2
      displayName: Install ReportGenerator Global Tool
        command: custom
        custom: tool
        arguments: install dotnet-reportgenerator-globaltool -g 

    - script: echo "##vso[task.prependpath]$HOME/.dotnet/tools"
      displayName: 'Add ReportGenerator to PATH'

    - script: reportgenerator "-reports:$(Build.SourcesDirectory)/TestResults/Coverage/coverage.cobertura.xml" "-targetDir:$(Build.SourcesDirectory)/TestResults/Coverage/Reports" "-tag:$(Build.BuildNumber)" "-reportTypes:HtmlInline_AzurePipelines;Cobertura"
      displayName: 'Generate HTML Coverage Report'

    - task: SonarCloudAnalyze@1
    - task: SonarCloudPublish@1
        pollingTimeoutSec: '300'

    - task: PublishCodeCoverageResults@1  
      displayName: 'Publish Code Coverage'  
        codeCoverageTool: Cobertura  
        summaryFileLocation: '$(Build.SourcesDirectory)/TestResults/Coverage/coverage.cobertura.xml'
        reportDirectory: '$(Build.SourcesDirectory)/TestResults/Coverage/Reports'

My test project has references to coverlet.msbuild (3.1.2) as was suggested as a solution on another post, but nothing seems to be working for me, Sonar cloud is just showing 0% but I know from the reports that are getting generated in the pipeline that the coverage is higher. I can see the coverage.cobertura.xml file in the artifacts as well so it is getting generated.

In the logs for the SonorCloudAnalyze I can’t find any reference to the file coverage.cobertura.xml, not a file not found or incorrect format message or anything.

Any help or pointers on what to try on this one is appreciated as it’s been driving me insane now for for too long.

Hey there.

To start, sonar.opencover.reportPaths doesn’t’ exist, while sonar.cs.opencover.reportsPaths does.

If you plan to use sonar.cs.opencover.reportsPaths to import code cover, you probably want to change /p:CoverletOutputFormat in your dotnet test command to /p:CoverletOutputFormat=opencover.

If this isn’t successful, I would suggest looking in the logs of the SonarQubeAnalyze step, which should provide information about whether or not the report was found / what happened when the report attempts to be processed.