Must-share information (formatted with Markdown):
- SonarScanner for MSBuild 5.4.1
- SonarScanner is on Windows System installed.
Hello all,
I have the following problem. I have a C# application that has some unit tests. I run these normally on my Jenkins server in the Declarative pipeline.
For this I have a stage that runs these tests first, it looks like this:
stage('Stage 1 - UnitTest') {
when{
anyOf {
branch 'develop'
}
}
steps {
echo 'Test'
bat 'vstest.console UnitTests.dll --logger: "trx;LogFileName=MyResults.trx" --ResultsDirectory:.'
bat 'OpenCover.Console.exe -register:user -targetargs:"%WORKSPACE%\\UnitTests.dll" -output:\"%WORKSPACE%\\coverage.xml\"'
bat 'OpenCoverToCoberturaConverter.exe "-input:coverage.xml" "-output:cobertura.xml"'
}
}
Next, I have a second stage. This will do the unit tests again and then upload them to SOnar Qube.
stage('Stage 2 - SonarQube') {
when{
anyOf {
branch 'develop'
}
}
steps {
withSonarQubeEnv('Sonarqube') {
echo 'MSBuild'
bat "${scannerHome}\\SonarScanner.MSBuild.exe begin /k:BuildWorld /n:BuildWorld /v:${env.BUILD_ID} /d:sonar.cfamily.threads=2 /d:sonar.c.file.suffixes=- /d:sonar.cpp.file.suffixes=- /d:sonar.objc.file.suffixes=- /d:sonar.cs.opencover.reportsPaths=%WORKSPACE%\\coverage.xml"
bat 'vstest.console UnitTests.dll --logger: "trx;LogFileName=MyResults.trx" --ResultsDirectory:.'
bat "${scannerHome}\\SonarScanner.MSBuild.exe end"
}
}
}
Problem: The problem is my unit tests take 20-30 minutes and if I run them twice you can imagine how long it takes.
Is there a solution to combine these two steps somehow, i.e. to create a file in the vstest that sonar scanner can import and upload ?
Why have I done this so far, you may ask.
The problem is that Jenkins does not recognize SonarQube when a test fails. So I have to start the tests freely.