Code coverage is not feed to sonarqube

I am facing the issue for below yaml. Code coverage report is not pushed into sonarqube, Please help me on this issue

SonarQube

- task: SonarQubePrepare@5
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: 'SonarQubeName'
    scannerMode: 'MSBuild'
    projectKey: '$(repository)'
    projectName: '$(repository)'
    extraProperties: |
      /d:sonar.coverageReportPaths = $(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml
      /d:sonar.cs.vscoveragexml.reportsPaths=$(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml
      /d:sonar.cs.opencover.reportsPaths=$(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml
      /d:sonar.cs.JaCoCo.reportsPaths=$(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml
      /d:sonar.cs.vstest.xmlReportPaths=$(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml
      sonar.cs.xunit.reportsPaths=$(Agent.TempDirectory)/testresults.trx
      sonar.language=cs
      sonar.scm.disabled=true
      sonar.verbose=true
      sonar.branch.name=$(Build.SourceBranchName)

# DotNet build
- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '$(serviceSolution)'
    arguments: '--configuration Release --version-suffix $(Build.BuildNumber)'

# Run tests and generate coverage report
- task: DotNetCoreCLI@2
  displayName: 'Run tests and generate coverage report'
  inputs:
    command: 'test'
    projects: '$(serviceSolution)'
    arguments: '--configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(System.DefaultWorkingDirectory)/TestResults/Coverage/ --logger "trx;LogFileName=testresults.trx"'
    
# Publish test results
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: '$(Agent.TempDirectory)/testresults.trx'
    searchFolder: '$(Agent.TempDirectory)'
    mergeTestResults: false
    failTaskOnFailedTests: false

# Publish code coverage
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/TestResults/Coverage/coverage.cobertura.xml'
    reportDirectory: '$(System.DefaultWorkingDirectory)'


# SQ Run Code Analysis task - QC3
- task: SonarQubeAnalyze@5
  displayName: RUN SonarQube

# Complete the analysis and upload the results to the server
- task: SonarQubePublish@5
  displayName: 'Publish analysis results to SonarQube'

What do the logs say?

And, SonarQube doesn’t support a Cobertura file for C# coverage. I suggest referring to the documentation on .NET Test Coverage

1 Like

Hi @colin, I am facing this log issue now . If SonarQube doesn’t support a Cobertura file for C# coverage means can you please tell me the yaml syntex for other supporting coverage tool. I am not able to find the yaml code in the link you have shared

Hey there.

We don’t have YAML to share for every coverage tool / configuration, but you will need to research how to implement a compatible coverage tool/reporter into your pipeline. It might just be a matter of changing the CoverletOutputFormat

1 Like

@colin your first answer is correct, I have changed the coverage tool and it working perfectly, Thank you very much :slight_smile:

just changed the output format

/p:CoverletOutputFormat=cobertura to /p:CoverletOutputFormat=opencover

and changed the coverage xml file also from coverage.cobertura.xml to coverage.opencover.xml

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.