I’m trying to setup an AzureDevOps pipeline to report code coverage status as part of code quality metrics. The codebase includes both C# and Angular code.
I’m able to create separate coverage reports (in Cobertura format) and merge them under a common report which is visible under the Code Coverage tab in my Pipeline runs.
However, SonarQube is not able to find the Cobertura reports and keeps looking for .coverage files in the pre-defined location which results in error and 0% coverage reported in SonarQube side.
##[error]Failed to convert the binary code coverage reports to XML. No code coverage information will be uploaded to the server (SonarQube/SonarCloud).
##[error]Check that the downloaded code coverage file (C:\agent\_work\1\TestResults\***.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.
Is there a way to make this work? Below is a snippet from my pipeline, it seems the extraProperties has no effect on SonarQubePrepare task:
I suggest stepping back and reviewing both documentation pages so that you can generate the coverage reports in the right format to be read by SonarQube!
Thanks for your reply and pointing out that Cobertura is not used. I have confused it with other formats.
I need some clarifications:
It seems that SonarQube task always tries to take .coverage files even if they don’t exist. It will still try to find those files even if I supply a value to sonar.cs.opencover.reportsPaths. Is this the intended behavior? How do I disable taking visual studio test results if I want to use other format
Is there a way to change the base path for JavaScript code? SonarQube is able to read the coverage file from sonar.lcov.javascript.reportPaths but it complains about being unable to resolve the paths (test are executed from a sub directory and the coverage report lists the files relative to that directory).-
Thanks for the reply. I have managed to fix the first issue and now able to pass coverage in opencover format. I had to use “XPlat Code Coverage;Format=cobertura,opencover” and pass the paramete to SonarQube accordingly.
I’m still facing issue with parsing lcov files. I 'm getting an error as below:
2025-01-28T09:09:27.7459694Z INFO: Analysing [C:\agent\_work\1\s\src\apps\Dashboard.WebApp\DashboardApp\coverage\DashboardApp\lcov.info]
2025-01-28T09:09:27.7688923Z WARN: Could not resolve 113 file paths in [C:\agent\_work\1\s\src\apps\Dashboard.WebApp\DashboardApp\coverage\DashboardApp\lcov.info]
2025-01-28T09:09:27.7690492Z WARN: First unresolved path: C:\agent\_work\1\s\src\apps\Dashboard.WebApp\DashboardApp\src\polyfills.ts (Run in DEBUG mode to get full list of unresolved paths)
I make sure the lcov file contains the full absolute path but it is not working. Does it require to use unix path format to be able to parse? The below line seems to indicate that it only splits by ‘/’.
My project is a mixture of C# and Angular, I couldn’t find a way to set a different path for the Angular code. Setting sonar.source will mess up the dotnet part.
Hi @Colin, I’m not able to use Windows absolute paths. The above example path C:\agent\_work\1\s\src\apps\Dashboard.WebApp\DashboardApp\src\polyfills.ts will show the warning for unresolved path. However, if I change the format to use / instead C:/agent/_work/1/s/src/apps/Dashboard.WebApp/DashboardApp/src/polyfills.ts, the warning disappears but the coverage is still not included correctly.
Would it be possible to know when this issue can be addressed?
Thanks for reporting the issue. We have been trying to reproduce it, without success. It does not mean that it does not exist, though. There is likely something that we are missing with our testing setup. For context, we have been working for the last few weeks on improving (i.e. fixing) our LCOV support, and the more cases we can investigate, the better.
Would you mind preparing a minimal reproducer project, and share it with us through the platform of your choice?