MsBuild.SonarQube.Runner.exe end gives exit code 0 when analysis has failed when running from powershell.

236 views
Skip to first unread message

daniel hegner

unread,
Jan 12, 2018, 7:59:03 AM1/12/18
to SonarQube
Hi!

When I'm ending the Sonar Analysis the runner and it fails for some reason (the actual error is irrelevant for this question), one would expect that it would return an exit code != 0.
However when I run it in powershell on TeamCity like this:

%system.PATHTO.MSBUILD_SONARQUBE_RUNNER%\MSBuild.SonarQube.Runner.exe end
Write-Host "Lastexitcode: $lastexitcode"
if ($lastexitcode)
{
  Write-Error "MsBuild.SonarQube.Runner.exe end failed"
  exit(1)
} else {
  Write-Output "MsBuild.SonarQube.Runner.exe end as expected"
}

I get this in the build log :
[...Some error that fails the analysis]
[10:58:40][Step 8/8] Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
[10:58:40][Step 8/8] 10:58:40.512 Creating a summary markdown file...
[10:58:40][Step 8/8] 10:58:40.516 Post-processing failed. Exit code: 1
[10:58:40][Step 8/8] Lastexitcode: 0
[10:58:40][Step 8/8] MsBuild.SonarQube.Runner.exe end as expected
[10:58:40][Step 8/8] Process exited with code 0

The line "10:58:40.516 Post-processing failed. Exit code: 1" is written on stderr and the rest on stdout.

Why is $lastexitcode = 0 in this case? How can I detect this error?





duncan.po...@sonarsource.com

unread,
Jan 12, 2018, 1:09:42 PM1/12/18
to SonarQube
Hi Daniel,

You're running an old version of the scanner executable MSBuild.SonarQube.Runner.exe.

Have a look in your SonarQube runner folder. You should find the new version of the executable, called SonarQube.Scanner.MSBuild.exe
If you don't, install the latest version, and make sure your script calls SonarQube.Scanner.MSBuild.exe

FYI then name of the executable was changed some time ago. In an effort to maintain backwards compatibility we continued to ship an executable with the old exe name. All it does is launch the newer version of the exe. Unfortunately, it doesn't return the exit code from the newer version - it always returns zero.  I've logged bug SONARMSBRU-366 to track this. Apologies for that.

Regards,
Duncan

daniel hegner

unread,
Jan 16, 2018, 6:45:22 AM1/16/18
to SonarQube
Wow, I really need to check my glasses. :)

I changed to SonarQube.Scanner.MSBuild.exe and now it returns non-zero when failing.

Thanks.
Reply all
Reply to author
Forward
0 new messages