version of SonarQube: Community Build 25.1.0.102122 (deployed via Helm in Kubernetes)
version of sonar-scanner: SonarScanner CLI 7.0.2.4839
The issue I’m experiencing is that I’m creating a code coverage report for the .NET project that I’m scanning and passing it to SonarQube, but SonarQube does not display the Code Coverage percentage in the Web UI.
The structure of the code repository is as follows:
-- main .NET folder for the projects
---- project #1
---- project #2
---- main.sln file
-- pipeline1
-- pipeline2
-- .gitignore
-- README.md
And the Pipeline that I’m using:
trigger: none
pool: myPool
variables:
appProjectPath: '$(Build.Repository.LocalPath)\MainProjectFolder\FrontendAPP'
apiProjectPath: '$(Build.Repository.LocalPath)\MainProjectFolder\BackendAPI'
testsProjectPath: '$(Build.Repository.LocalPath)\MainProjectFolder\UnitTests'
buildConfiguration: 'Release'
resources:
repositories:
- repository: myRepo
trigger: none
type: git
ref: main
name: mySeparateProject/myExternalRepo
steps:
- checkout: myRepo
path: my-repo
displayName: Clone myRepo
- task: CmdLine@2
inputs:
script: 'dependency-check --scan $(System.DefaultWorkingDirectory) --nvdApiKey %NVDAPIKEY% -o $(System.DefaultWorkingDirectory)\dependency-check'
displayName: Dependency check
env:
NVDAPIKEY: $(NVDAPIKEY)
retryCountOnTaskFailure: 5
- task: SonarQubePrepare@7
inputs:
SonarQube: 'myServiceConnection'
scannerMode: 'dotnet'
projectKey: 'myProjectKey'
projectName: 'myProject'
extraProperties: |
sonar.filesize.limit=300
# sonar.sources=.
sonar.scanner.skipJreProvisioning=true
sonar.scanner.truststorePath=C:\\Program Files\\Java\\jdk-17\\lib\\security\\cacerts
sonar.scanner.truststorePassword=changeit
sonar.dependencyCheck.htmlReportPath=$(System.DefaultWorkingDirectory)\dependency-check\dependency-check-report.html
sonar.cs.vscoveragexml.reportsPaths=$(System.DefaultWorkingDirectory)\coverage.xml
sonar.exclusions=dependency-check/*.html,*.yml,*.md,MainProjectFolder\_Documentation\**,MainProjectFolder\.vscode\**,MainProjectFolder\MainProjectFolder.Data\Migrations\**
- script: dotnet build $(appProjectPath) -c $(buildConfiguration)
displayName: 'Build APP'
- script: dotnet-coverage collect "dotnet test $(testsProjectPath) -c $(buildConfiguration)" -f xml -o "coverage.xml"
displayName: 'Build and Test API'
- task: SonarQubeAnalyze@7
inputs:
jdkversion: 'JAVA_HOME_17_X64'
- task: SonarQubePublish@7
inputs:
pollingTimeoutSec: '300'
The Pipeline executes without issues, when I go to the UI I can see the report from the dependency-check
plugin, but I can’t see the code coverage percentage. When I go into the pipeline logs to check for issues I can see under the logs for the SonarQubeAnalyze@7
task that the report is successfully generated:
INFO: Parsing the Visual Studio coverage XML report c:\agent\_work\100\my-repo\coverage.xml
INFO: Adding this code coverage report to the cache for later reuse: c:\agent\_work\100\my-repo\coverage.xml
INFO: Coverage Report Statistics: 1610 files, 1473 main files, 1473 main files with coverage, 137 test files, 0 project excluded files, 0 other language files.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=8756ms
NOTE:
I tried the same pipeline for a much smaller project and SonarQube displays the coverage percentage correctly. Also I checked if the report being generated is empty, but everything is fine with it and I can even see it in the main directory of the pipeline, bit SonarQube still shows 0% code coverage in the project.
NOTE2:
Project is being built on .NET 9 and the size of the report (coverage.xml
that is generated by the pipeline) is 150MB.
Is there something that I’m missing?