How to include external coverage.cobertura.xml generated file data in SonarQube Azure pipeline yaml

I am working on the Microservice and we are deploying the code using azure devops pipeline. Currently when we deploy the changes in sonarqube it is showing that 15% code coverage while when i run locally then it is showing 80% code coverage. I just want to how we can use the local generated file “coverage.cobertura.xml” file to calculate the code coverage.

Here are my steps I am doing:
– Generate Local Coverage
In Visual Studio 2019 → Program Console → we are using the following command.
dotnet test /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=cobertura

this command generate the file and show “80%” coverage.

Now, We created the pipeline in azure yaml and write the code over there and integrate with sonarqube and here is the code.

  • task: DotNetCoreCLI@2
    displayName: ‘Run Unit Tests - $(buildConfiguration)’
    command: ‘test’
    projects: ‘**/XXXX.XXX.Test/*.Test.csproj’
    arguments: ‘–configuration $(BuildConfiguration) /p:CollectCoverage=true “/p:CoverletOutputFormat="cobertura,opencover"” /p:CoverletOutput=$(System.DefaultWorkingDirectory)/TestResults/ --filter “(FullyQualifiedName!~SqlCommand)&(FullyQualifiedName!~AgentAWSSecret)”’

  • task: PublishCodeCoverageResults@1
    codeCoverageTool: ‘Cobertura’
    summaryFileLocation: ‘$(Build.SourcesDirectory)/**/coverage.cobertura.xml’
    pathToSources: ‘$(System.DefaultWorkingDirectory)/TestResults/’
    reportDirectory: ‘$(System.DefaultWorkingDirectory)/TestResults/’

In the above command it build in the pipeline and show 15% code coverage when i check that found that this low coverage is due to include the sqlcommand (folder). Our SQL database is in azure database.

Now i want to use the file generated locally (80%) coverage area through program console for sonarQube Line coverage.

Please let me how is it possible to give the local xml file to calculate from there.

Here are more detail:

  • ALM Used (Azure DevOps)
  • CI system used (Azure Devops
  • Language of the repository - English

Hey there.

You cannot use a Cobertura report to report coverage information for C# code.

You can however exclude SQL files from coverage reporting using code coverage exclusions, which should get you closer to the 15% number you see when you run tests/coverage locally.