Publish SonarQube Coverage Report for Set of Files

I have these below Tasks in my Gated.YML file which generates and Publishes the coverage in SonarQube Portal as below

  • task: DotNetCoreCLI@2
    displayName: “Run DI.Apps.Services tests”
    inputs:
    command: test
    projects: “**/Test.IP.Apps.Tests/*.csproj”
    arguments: ‘–no-restore --configuration $(BuildConfiguration) --collect “Code coverage”’

    • task: SonarQubePrepare@4
      displayName: Prepare analysis on SonarQube
      inputs:
      SonarQube: icsp.sonarqube
      projectKey: ‘$(Build.DefinitionName)’
      projectName: ‘$(Build.DefinitionName)’
      extraProperties: |
      sonar.qualitygate.wait=true
      sonar.qualitygate.timeout=3000 sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)//TestResults//coverage.opencover.xml
  • task: SonarQubeAnalyze@4
    displayName: ‘Run Code Analysis’

  • task: SonarQubePublish@4
    displayName: ‘Publish Quality Gate Result’

SonarQube SCreenshot

I want to generate code coverage modulewise Like TestModule for some set of like below files and Publish that Module Coverage in SonarQube

IP.Apps.Services\src\Test.IP.Apps.Business\TestProcessors*
IP.Apps.Services\src\Test.IP.Apps.API.Rest\Controllers\ModuleController.cs

Can you please let me know What is the best possible solution for the same

Hey there.

If you have another coverage report, you just need to supply comma-separated values to sonar.cs. open cover.reportsPaths!

If that’s not your question, I’d appreciate it if you try and add more details to your question. Please also include what version of SonarQube you’re using (you can find it in the footer of your instance), as requested in the template post.

So I have these tasks as mensioned below. Thease are generating for entire Test.IP.Apps.Tests/*.csproj Project but if i want to generate for only for some files and folders inside this project . How can we achive that?

  • task: DotNetCoreCLI@2
    displayName: “Run DI.Apps.Services tests”
    inputs:
    command: test
    projects: “**/Test.IP.Apps.Tests/*.csproj”
    arguments: ‘–no-restore --configuration $(BuildConfiguration) --collect “Code coverage”’
    • task: SonarQubePrepare@4
      displayName: Prepare analysis on SonarQube
      inputs:
      SonarQube: icsp.sonarqube
      projectKey: ‘$(Build.DefinitionName)’
      projectName: ‘$(Build.DefinitionName)’
      extraProperties: |
      sonar.qualitygate.wait=true
      sonar.qualitygate.timeout=3000 sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)//TestResults//coverage.opencover.xml
  • task: SonarQubeAnalyze@4
    displayName: ‘Run Code Analysis’
  • task: SonarQubePublish@4
    displayName: ‘Publish Quality Gate Result’

It sounds like you want to adjust the analysis scope using sonar.exclusions or sonar.inclusions

You can also exclude projects from analysis using this tag in the .xxproj file.