I am currently implementing an azure DevOps pipeline for my .Net microservices. I researched and read the sonar cloud doc, but nothing helped yet. I did generate the code coverage report using cobertura and that is working correctly in azure devops but I found out that you cannot link that type of format to sonarcloud so I was trying somehow to generate also the opencover and use it for exporting to sonarcloud, this is what I have done so far:
trigger:
- dev
- main
pool:
vmImage: ubuntu-latest
jobs:
- job: check_code_quality
steps:
- task: SonarCloudPrepare@1
displayName: 'Setup Sonar Cloud'
inputs:
SonarCloud: 'SonarCloud'
organization: '***'
scannerMode: 'MSBuild'
projectKey: '***'
projectName: '****'
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml
- task: DotNetCoreCLI@2
displayName: 'Build main code'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Run unit tests'
continueOnError: true
inputs:
command: 'test'
projects: '**/*[Tt]est*/*.csproj'
testRunTitle: 'Backend Unit Testing'
arguments: '--configuration Release --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover'
publishTestResults: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
- task: SonarCloudAnalyze@1
displayName: 'Run Sonar Analysis'
- task: SonarCloudPublish@1
displayName: 'Publish Sonar Results'
inputs:
pollingTimeoutSec: '300'
I checked the logs and I saw this:
Attachments:
/home/vsts/work/_temp/111bef07-6e19-43fe-a689-7597bc24dda3/coverage.cobertura.xml
/home/vsts/work/_temp/111bef07-6e19-43fe-a689-7597bc24dda3/coverage.opencover.xml
Also I have an issue that sonar cloud is only analyzing my test projects not the main code