Hey,
I need some help with adjusting our build pipeline for our C# .NET 8 project. I need some rubber-duck debugging, because I’m not sure what I need to do to fix this
We are using Azure Devops build pipelines and we are gradually moving over to linux (ubuntu-latest) for all the build steps. For this we are trying to move over to the dotnet-coverage
We are still using the SonarCloudPrepare@1 and SonarCloudAnalyze@1 tasks. The prepare tasks looks like this:
- task: SonarCloudPrepare@1
inputs:
SonarCloud: "xxx"
organization: "xxx"
scannerMode: "MSBuild"
projectKey: "xxx"
projectVersion: "$(Version.MajorMinor)"
extraProperties: |
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(Build.SourceVersion)
sonar.analysis.repository=$(Build.Repository.ID)
sonar.cs.vstest.reportsPaths=**/TestResults/*.trx
sonar.cs.vscoveragexml.reportsPaths=**/coverage.xml
(there are probably some unnecessary values there that we can remove, we are using sonarcloud since the project was .NET Framework 4.7)
The section where we run our unit tests and create the code coverage looks like this:
- script: |
dotnet tool install --global dotnet-coverage
dotnet-coverage collect "dotnet test $(Build.SourcesDirectory)/src/xxx/ --configuration Release --nologo --no-build --no-restore --logger trx" -f xml -o "coverage.xml"
The test results and code coverage are shown correctly in azure devops with these two steps:
- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/TestResults/*.trx'
searchFolder: '$(System.DefaultWorkingDirectory)'
failTaskOnFailedTests: true
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: $(Build.SourcesDirectory)/coverage.xml
The script tasks is generating the coverage.xml file and I’ve verified this. Also the sonarcloud analyze step is showing this in the logs:
INFO: Parsing the Visual Studio coverage XML report /home/vsts/work/1/./s/coverage.xml
INFO: Adding this code coverage report to the cache for later reuse: /home/vsts/work/1/./s/coverage.xml
INFO: Coverage Report Statistics: 2877 files, 2512 main files, 2512 main files with coverage, 365 test files, 0 project excluded files, 0 other language files.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=14316ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the Visual Studio Test Results file '/home/vsts/work/1/./s/src/xxx.Tests/TestResults/_fv-az630-59_2024-05-14_06_28_23.trx'.
about 15 other trx files are being found here
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=879ms
So, what can be a reason for sonarcloud to keep saying this on the PR Summary?
Coverage
A few extra steps are needed for SonarCloud to analyze your code coverage
[Setup coverage analysis](https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/overview/)
While azure devops received everything in order and shows me:
Tests and coverage
99.9% passed
41.27% covered
Best regards,
Freddy