in spite of the fact that dotnet-cover is setup and when I run it on command line it works, of course on the building agent and not on the sonarQube server? Should this be running on the soanrqube server !!!
Yes, I use self-hosted which is on a win 10 physical machine. I have Visual Studio Professional, I am aware of the fact that coverage feature is in Enterprise edition, however, that is why when I read instructions at .NET Test Coverage | SonarQube Docs
I understood that this can allow to not need Enterprise edition and that is why it is installed globally? Non?
Colin, after a long discussion on the github project for Coverlet at
petli very nice guy and really helped a lot. After a succesful run of the build pipeline, were created correctly and I was able to see nice reports inside Azure devops, I switched to sonarQube UI, still I see that sonarqube gets alerted of the new build but does not display coverage and unt test details. After investigating, I discovered that Azure devops creates coverage reports in the _temp directory of the build agent and not the project working directory which seems that sonarQube task does not search this upper directory (I came this thread which confimed this)across this thread
If I understood correctly you dont have Visual Studio Enterprise version in your self-hosted build agent, so you need to use dotnet-coverage tool (for example). The dotnet-coverage will convert .converage format to .xml format and you need to tell sonarscanner where is the xml file. See sonar.cs.vscoveragexml.reportsPaths
in Test Coverage Parameters | SonarQube Docs
So in your SonarQubePrepare-task you will need to add in extraProperties following: sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/myfile.coverage.xml (for the path see the -o parameter in bash script below)
In your Test-task either add following argument --results-directory $(Agent.TempDirectory) (or any folder you want) or do that in the .runsettings file
The .coverage files are seperated by the test cases and need to be merged and converted to one xml-file, so after Test-task add following bash script task to merge (-r argument) and convert (-f argument) .coverage files
- bash: dotnet-coverage merge -o $(Agent.TempDirectory)/myfile.coverage.xml -f xml -r $(Agent.TempDirectory)/*.coverage
displayName: 'Convert coverages to xml'
hope this helped =)
Edit: maybe merging to one xml file is not mandatory (so you could have multiple xml files) but that is what I ended with
sonar.projectBaseDir=$(Agent.TempDirectory)**\coverage.cobertura.xml(this is the way ** that azure devops reference su-directoris as the ml file is generated in temporary subdirectories and not directly in the _temp directoy)
in the prepare step but sonar gives an error, 2nd snapshot is for the error, indicating illegal carater, I tied to enclose with double quotes but also refuses
Ok, after removing results directory from test step and keeping sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)**\coverage.cobertura.xml
in prepare step, build goes through but it seems there is an issue sonar acceptig self-igne certificate as follows
I guess they didn’t. They just gave you an example runsettings file where was XPlat Code Coverage specified and the last comment was
“The issues you have now is something with how your build system runs your tasks, and I can’t assist with that. For sonarqube you have to read their documentation on how to specify the coverage report path. You may find https://reportgenerator.io/useful if you need to convert between report formats or if you have multiple coverlet output files that must be merged into a single report.”
But now I remember that I also had problems with those DotNetCoreTasks which you are using (I’m using YAML pipelines anyways and not the classic UI defined pipelines).
So the Test-task actually incjects to --logger trx and --results-directory arguments to the dotnet test command what you see in your logs it can be seen from Info icon next to ‘Publish test results and code coverage’
so if you use that the reports are always going to $(Agent.TempDirectory).
I would recommend to change back to --collect "Code coverage" setting, adding the bash script task with following command dotnet-coverage merge -o $(Agent.TempDirectory)/myfile.coverage.xml -f xml -r $(Agent.TempDirectory)/*.coverage
and setting in prepare analysis sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/myfile.coverage.xml (NOTE: specific file that we do with bash script)
For the certificate error in Publish Quality Gate results you need to add correct certificate chain to your self-hosted build agent’s Trusted Certs.
Ok I will update the build pipeline with your suggestion but can you tell me how it will find
which is not directly under $(Agent.TempDirectory)? it is a lower level directory created on the fly as the screenshot I posted earlier