Hi!
I have SonarQube installed on a Windows agent in Jenkins.
I want to see code coverage percentage and unit tests in SonarQube. I used the official documentation for all the commands.
Here is my example:
withSonarQubeEnv(credentialsId: 'mycred', installationName: 'SonarQube') {
def scannerHome = tool 'SonarScanner'
bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll begin /k:\"${proj_key}\" /d:sonar.host.url=\"${env.SONAR_LINK}\" /d:sonar.cs.opencover.reportsPaths=\"tests\\TestResults\\*.xml\" /d:sonar.cs.vstest.reportsPaths=\"**/*.trx\" -v:diag"
bat "dotnet build --no-incremental"
bat "dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='./TestResults/'"
bat "dotnet test --collect:\"XPlat Code Coverage\""
bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll end"
}
In Jenkins, a folder tests\\TestResults
is created, where I see test_results.trx
, and it shows me the tests in SonarQube - there are no problems with that.
For code coverage, two files are created:
tests\TestResults\c377z55b-poq3-421e-8bad-0dc790a2841cAdministrator_JENKINS-AGENT_2024-04-10.12_57_33.coverage
andtests\TestResults\c117f25b-fbc3-421e-8bad-0dc593f2839b\coverage.cobertura.xml
I don’t understand which of these files should be passed to SonarQube and how to display the percentage there?
SonarQube works only with one branch for me. Please advise.