# Code coverage is not feed to sonarqube

**URL:** <https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926>\
**Category:** SonarQube Server / Community Build\
**Tags:** sonarqube, dotnet, coverage\
**Created:** [May 15, 2023, 2:41pm UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926 "2023-05-15T14:41:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thanabalan\_B](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/thanabalan_b/32/45154_2.png) [@Thanabalan\_B](https://community.sonarsource.com/u/Thanabalan_B)\
**Post date:** [May 15, 2023, 2:41pm UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/1 "2023-05-15T14:41:17Z")

</div>

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'

```

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [May 16, 2023, 2:55pm UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/2 "2023-05-16T14:55:26Z")

</div>

What do the logs say?

> [@How to find logs about importing code coverage](https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317/2):
>
> Any documentation linked in this guide is for SonarQube – however you can find similar (if not the same) documentation for SonarCloud at [https://docs.sonarcloud.io/](https://docs.sonarcloud.io/)

And, SonarQube doesn’t support a Cobertura file for C# coverage. I suggest referring to the documentation on [.NET Test Coverage](https://docs.sonarqube.org/latest/analyzing-source-code/test-coverage/dotnet-test-coverage/)

---

<div class="post-metadata">

**Author:** ![Thanabalan\_B](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/thanabalan_b/32/45154_2.png) [@Thanabalan\_B](https://community.sonarsource.com/u/Thanabalan_B)\
**Post date:** [May 16, 2023, 6:51pm UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/3 "2023-05-16T18:51:25Z")

</div>

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

 ![Code coverage parsing issue](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/a/f/af051c3ad964233cf3185fa3afa6fa12d672c399.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [May 17, 2023, 8:38am UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/4 "2023-05-17T08:38:47Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Thanabalan\_B](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/thanabalan_b/32/45154_2.png) [@Thanabalan\_B](https://community.sonarsource.com/u/Thanabalan_B)\
**Post date:** [May 17, 2023, 10:13am UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/5 "2023-05-17T10:13:29Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [May 24, 2023, 10:13am UTC](https://community.sonarsource.com/t/code-coverage-is-not-feed-to-sonarqube/90926/6 "2023-05-24T10:13:35Z")

</div>

Closed on May 24, 2023, 10:13am UTC

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