I’m trying to hook up my .Net Core & angular project in sonarcloud. I build and launch my tests using Azure Devops Yaml pipeline. Here is a summary of what’s happening.
First I have a Prepare analysis task :
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on Sonarcloud'
inputs:
SonarCloud: 'Sonarcloud'
organization: ***redacted***
scannerMode: 'MSBuild'
projectKey: ***redacted***
projectName: ***redacted***
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.branch.name=$(Build.SourceBranchName)
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
Then I build the project, everything is fine here. Then I launch the tests, and create a html report for my azure pipeline using report generator:
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
projects: 'Tests/**/*.csproj'
nobuild: true
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator "-reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml" "-targetdir:$(Build.SourcesDirectory)/CodeCoverage" "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
displayName: Create Code coverage report
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'
Here again everything is fine, the tests run, the coverage is computed, the report is generated.
Then I install typescript (for sonar analysis) and I run the code analysis:
- script: |
cd $(Build.SourcesDirectory)/Src/***ProjectDir***
npm install typescript
displayName: 'Install typescript for sonar analysis'
- task: SonarCloudAnalyze@1
displayName: 'Run code analysis'
continueOnError: false
- task: SonarCloudPublish@1
displayName: 'Publish code analysis'
continueOnError: false
inputs:
pollingTimeoutSec: '300'
The sonar analysis finds the trx file but not the opencover coverage reports even though the path is provided in the sonar.cs.opencover.reportsPaths parameter in the prepare analysis task.
Here is the logs:
D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.10.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.8
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
17:31:43.118 Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
17:31:43.197 Did not find any binary coverage files in the expected location.
17:31:43.197 Falling back on locating coverage files in the agent temp directory.
17:31:43.197 Searching for coverage files in D:\a\_temp
17:31:43.243 No coverage files found in the agent temp directory.
Analysis is correctly uploaded on sonarcloud but the coverage shows 0%…
Any idea on how to solve this ?
Thanks