Environment: I have Azure DevOps pipeline and SonarCloud integration. It’s a .NET project.
The problem - SonarCloudAnalyze@2
fails to process test coverage information when that information is in *.cobertura.xml
format. It only processes the coverage information when it’s in binary .coverage
format.
Question - is Cobertura format not supported by SonarCloudAnalyze@2
, or is the problem somewhere else?
First, pipeline code that works (coverage collected in .coverage format):
- task: DotNetCoreCLI@2
displayName: 'Dotnet test ${{parameters.buildConfiguration}}'
inputs:
command: 'test'
publishTestResults: false
arguments: >
-v normal
-l:trx
--collect "Code coverage"
- task: SonarCloudAnalyze@2
displayName: SonarCloud Analysis
It generates output like this, without errors:
Attempting to locate a test results (.trx) file...
Looking for TRX files in: C:\a\1\TestResults, C:\a\1\s\TestResults
The following test results files were found: C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_37.trx, C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_49.trx
Absolute path to coverage file: C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_37\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_37.coverage
Absolute path to coverage file: C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_49\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_49.coverage
The following code coverage attachments were found from the trx files: C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_37\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_37.coverage, C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_49\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_49.coverage
Not using the fallback mechanism to detect binary coverage files.
Converting coverage file 'C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_37\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_37.coverage' to 'C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_37\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_37.coveragexml'.
Converting coverage file 'C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_49\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_49.coverage' to 'C:\a\1\s\TestResults\AzDevOps_aisar90cd000BMN_2024-06-07_12_58_49\In\aisar90cd000BMN\AzDevOps_aisar90cd000BMN_2024-06-07.12_58_49.coveragexml'.
Coverage report conversion completed successfully.
The TFS Processor has finished
Now, pipeline code that does not work (coverage in Cobertura format):
- task: DotNetCoreCLI@2
displayName: 'Dotnet test ${{parameters.buildConfiguration}}'
inputs:
command: 'test'
publishTestResults: false
arguments: >
-v normal
-l:trx
--collect "Code coverage;Format=Cobertura"
- task: SonarCloudAnalyze@2
displayName: SonarCloud Analysis
It generates output like this, with errors:
Fetching code coverage report information from TFS...
Attempting to locate a test results (.trx) file...
Looking for TRX files in: C:\a\13\TestResults, C:\a\13\s\TestResults
The following test results files were found: C:\a\13\s\TestResults\AzDevOps_aisar90cd000BM4_2024-06-07_13_18_25.trx, C:\a\13\s\TestResults\AzDevOps_aisar90cd000BM4_2024-06-07_13_18_36.trx
##[error]Failed to convert the binary code coverage reports to XML. No code coverage information will be uploaded to the server (SonarQube/SonarCloud).
Check that the downloaded code coverage file (C:\a\13\s\TestResults\AzDevOps_aisar90cd000BM4_2024-06-07_13_18_25\In\aisar90cd000BM4\AzDevOps_aisar90cd000BM4_2024-06-07.13_18_25.cobertura.xml) is valid by opening it in Visual Studio. If it is not, check that the internet security settings on the build machine allow files to be downloaded from the Team Foundation Server machine.
Failed to convert the binary code coverage reports to XML. No code coverage information will be uploaded to the server (SonarQube/SonarCloud).
Why is this happening? The only addition that makes it fail is Format=Cobertura
. Is Cobertura not supported by SonarCloud, or am I supposed to apply some additional configuration to SonarCloud so that it would look for Cobertura XML files, not binary files? Thanks.