4

I'm trying out SonarQube using the new MSBuild SonarQube Runner v1.0. If I install a fresh SonarQube server locally, the following command works fine, and I can build my solution directly afterward, call the 'end' command, and have the results published in SonarQube:

MSBuild.SonarQube.Runner.exe begin /key:TestKey /name:TestName /version:1.0.0.0

However, if I run this against an existing SonarQube server that exists on the internal network, it always returns with exit code 1:

15:32:40 Creating config and output folders... 15:32:40 Creating directory: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\conf 15:32:40 Creating directory: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\out 15:32:41 Generating the FxCop ruleset: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\conf\SonarQubeFxCop-cs.ruleset Process returned exit code 1

It seems to download a lot of the dependencies into /.sonarqube, so communication with the server isn't an issue

Things I've tried:

  • checked the access.log, server.log and event logs
  • upgraded the existing server to v5.1.2 (clean install using the guide)
  • upgraded the sonar-csharp-plugin to v4.1
  • right-clicked all .jar files on the server and ensured they are unblocked
  • tried the runner directly on the server
  • (ongoing) tried debugging the source code (happening somewhere in the pre-process step: success comes back as true, but the error code is 1)
  • disabled UAC on the server an rebooted
  • re-installed JRE on both server and client, ensure JAVA_HOME in both PATH and registry are set correctly

Any help or pointers greatly accepted. I've been stuck on this for 2 days and can't think of anything else to try except continue trawling through source code. Thank you.

Pascal Berger
  • 4,262
  • 2
  • 30
  • 54
Warren
  • 571
  • 1
  • 4
  • 6

1 Answers1

4

This is a tricky one! Looking at the code, I see only one path that can yield this output:

  1. It fails while generating the FxCop ruleset for C#, as the VB.NET FxCop ruleset message is not logged - see TeamBuildPreProcessor.cs#L149 and TeamBuildPreProcessor.cs#L185
  2. The GenerateFxCopRuleset() call for C# threw a WebException, leading to the call of Utilities.HandleHostUrlWebException() - which has to return true for the exception to be silently swallowed - see Utilities.cs#L153
  3. The only path returning true without logging any message is if a HttpStatusCode.NotFound was received - see Utilities.cs#L158
  4. The control flow goes back to FetchArgumentsAndRulesets(), which returns false, then goes back to Execute() which returns false as well - see TeamBuildPreProcessor.cs#L106
  5. The MSBuild SonarQube Runner "begin" phase (called "preprocessor" in the code) fails - see Program.cs#L42

So, at some point, some SonarQube web service required for the C# FxCop ruleset generation is return a HTTP 404 error.

Could you monitor your network traffic and listen for the failing HTTP call? [I will keep on updating this answer afterwards]

EDIT: Indeed the error is caused by the quality profile name containing special characters. Such characters are currently badly URL-escaped, which leads to a 404.

I've created the following ticket to fix this issue in the upcoming release: http://jira.sonarsource.com/browse/SONARMSBRU-125

Dinesh Bolkensteyn
  • 2,971
  • 1
  • 17
  • 20
  • 1
    Hi Dinish, thanks for your input. I managed to find the issue last night using your pointers, but it was a little unexpected: In `Quality Profiles`, there was an existing `C#` default profile named 'Sonar+Resharper'. I replaced the `+` from the name with a space `Sonar Resharper`, and now the registration / begin command works from the runner. – Warren Aug 07 '15 at 10:15
  • I faced the same issue as Warren described in his question. Apparently I had my Quality Profile named as `xxxx C#`. After I removed the `#` from profile name it worked liked a charm. – user1178376 Aug 08 '15 at 17:17
  • Thanks - I've edited my answer and created a ticket to fix the bad URL escaping in the next release. – Dinesh Bolkensteyn Aug 08 '15 at 20:57
  • @Dinesh-SonarSourceTeam can you please look into this issue http://stackoverflow.com/questions/28027524/sonar-fxcop-results-not-displayed – Midhun Murali Aug 14 '15 at 07:13
  • @Dinesh-SonarSourceTeam Please the new questions here https://stackoverflow.com/questions/32004565/sonar-dashboard-not-updated-after-fxcop-analysis – Midhun Murali Aug 14 '15 at 07:29