SonarQube Scanner for MSBuild fails with [Unable to complete SonarQube analysis]

9,977 views
Skip to first unread message

tre...@gmail.com

unread,
Oct 25, 2017, 9:58:33 AM10/25/17
to SonarQube
Hey,

I am using SonarQube Scanner for MSBuild 3.0.2.656 and sonarqube server version 6.4 (build 25310).
It is a multi language build with java, cpp and csharp modules - java and cpp are working fine, but I have problems with csharp. Msbuild is the one bundled with Microsoft.NET framework (v4.0.30319). 
I am invoking the scanner as an executable using ANT. SonarQube.Analysis.xml is a custom one containing all required properties: 

<Property Name="sonar.host.url">http://myUrl</Property>
<Property Name="sonar.login">myUser</Property>
<Property Name="sonar.password">myPass</Property>
<Property name="sonar.projectKey">myProject:key</Property>
<Property name="sonar.projectName">myProject.name</Property>
<Property name="sonar.projectVersion">24154cv45</Property>

After executing the steps as per the documentation (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild) I get failures with the last command (project is build non the less)
Last lines in my log:
  
"c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\client\Nirvana DotNet.sln" (Rebuild target) (1) ->
"c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj" (Rebuild target) (80) ->
  RealmMonitor.cs(270,30): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(320,42): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(495,38): warning CS0168: The variable 'ex' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(1324,36): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(1356,34): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(798,38): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(804,42): warning CS0168: The variable 'e2' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(942,55): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(1190,34): warning CS0168: The variable 'e' is declared but never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]
  RealmMonitor.cs(878,26): warning CS0414: The field 'com.pcbsys.nirvana.nAdminAPI.apps.RealmMonitor._channelMonitor.maxMemory' is assigned but its value is never used [c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\applications\RealmMonitor\RealmMonitor.csproj]

    1057 Warning(s)
    0 Error(s)

Time Elapsed 00:00:36.15
===============
Executing command:
SonarQube.Scanner.MSBuild.exe end
===============
SonarQube Scanner for MSBuild 3.0.2
Default properties file was found at c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\SonarQube.Analysis.xml
Loading analysis properties from c:\users\nirdevadm\jenkins\workspace\10.2.S_sonar\prod\csharp\SonarQube.Analysis.xml
Post-processing started.
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
  3. The begin, build or end steps have not all been launched from the same folder
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
14:26:53.995  Creating a summary markdown file...
14:26:53.997  Post-processing failed. Exit code: 1

Any ideas why this happens and how to solve it? 
Thanks

G. Ann Campbell

unread,
Oct 25, 2017, 10:25:37 AM10/25/17
to SonarQube
Hi,

It's not clear to me what version of MSBuild you're running, but I suspect it's the problem. Google is telling me that for several years now MSBuild has been distributed with Visual Studio rather than with the .NET Framework. Since you're using a .NET Framework version, that's the likely cause of your problem. Make sure you're using at least v14.0 as stated in #2 below.


Ann

Vassilena Treneva

unread,
Oct 31, 2017, 10:20:43 AM10/31/17
to G. Ann Campbell, SonarQube
​Hey,

Thanks for your reply. Changing the path to the "other" msbuild helped.

I run into another problem however - I believe I set all required properties in the xml configuration but despite this I get:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: key

   at SonarQube.Common.ListPropertiesProvider.TryGetProperty(String key, Property& property)
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\XMLExport\bin\Debug\XMLExport.exe.RoslynCA_fixed.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\XMLImport\bin\Debug\XMLImport.exe.RoslynCA_fixed.json
   at SonarQube.Common.AggregatePropertiesProvider.TryGetProperty(String key, Property& property)

I am attaching the xml configuration that I use (SonarQube.Analysis.xml) and the console output (cmd.txt)


--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/mtPIPobAefA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/9b0623a3-53de-4f26-b9a4-60d46212f7c7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

SonarQube.Analysis.xml

G. Ann Campbell

unread,
Oct 31, 2017, 10:25:58 AM10/31/17
to SonarQube
Hi,

SonarQube.Analysis.xml sets project-level (sub-module-level in the Java world) properties. You can't use it to set project key, SonarQube location & so on. Those must be set in the command line. Also, instead of passing login and password, you should look into using an authentication token.


Ann

Vassilena Treneva

unread,
Oct 31, 2017, 10:34:01 AM10/31/17
to G. Ann Campbell, SonarQube
Hey Ann,

I am sorry, I got lost...

The official documentation (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild) says we need to specify sonar.host.url and sonar.login in the SonarQube.Analysis.xml
Are you saying this is incorrect and I need to pass these when calling msbuild? 

Our server configuration works with user/pass settings and at the moment I cannot change this. I assume this would work, although it might not be recommended? 

Many thanks for your input.



G. Ann Campbell

unread,
Oct 31, 2017, 10:42:44 AM10/31/17
to Vassilena Treneva, SonarQube
Hi,

What you're pointing to is a global configuration file. I wouldn't expect to see project name, key and version to be set there. On the other hand this SonarQube.Analysis.xml is project/sub-module level. Neither level is appropriate for passing project name, key, and version. Try moving those to the command line.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

Vassilena Treneva

unread,
Oct 31, 2017, 11:00:02 AM10/31/17
to G. Ann Campbell, SonarQube
Okay Ann - I will try.
Does it matter which command they get added to? I guess this should be command #1, i.e:
  
SonarQube.Scanner.MSBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"Project Name" /v:"1.0" /n:[SonarQube Project Name] /k:[SonarQube Project Key] /v:[SonarQube Project Version]
MSBuild.exe /t:Rebuild
SonarQube.Scanner.MSBuild.exe end

G. Ann Campbell

unread,
Oct 31, 2017, 11:34:52 AM10/31/17
to Vassilena Treneva, SonarQube
Hi,

You must pass the credentials on both begin and end commands. For the rest, you've guessed correctly.


:-)
Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

Vassilena Treneva

unread,
Nov 1, 2017, 5:46:08 AM11/1/17
to G. Ann Campbell, SonarQube
​Hey Ann,

Can you advise what is that I am doing wrong? Looks like I am passing invalid switches...
With the latest changes you suggested I get:

Executing command:
SonarQube.Scanner.MSBuild.exe end /n:"com.softwareag.num" /k:"com.softwareag:num" /v:"2017-11-01_11:29:53"
===============
SonarQube Scanner for MSBuild 3.0.2
Default properties file was found at E:\rel\10.2.0.x\prod\csharp\SonarQube.Analysis.xml
Loading analysis properties from E:\rel\10.2.0.x\prod\csharp\SonarQube.Analysis.xml
Post-processing started.
11:38:40.684  11:38:40.682  Unrecognized command line argument: /n:com.softwareag.num
11:38:40.684  11:38:40.684  Unrecognized command line argument: /k:com.softwareag:num
11:38:40.685  11:38:40.684  Unrecognized command line argument: /v:2017-11-01_11:29:53
11:38:40.685  Post-processing failed. Exit code: 1

Full command line attached in cmd.txt

G. Ann Campbell

unread,
Nov 1, 2017, 7:27:45 AM11/1/17
to Vassilena Treneva, SonarQube
Hi,

You must pass credentials on both commands, not name, key, version.

So: SonarQube.Scanner.MSBuild.exe end /d:sonar.login=******


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

G. Ann Campbell

unread,
Nov 1, 2017, 10:18:40 AM11/1/17
to Vassilena Treneva, SonarQube
Hi,

Don't forget to include the Google Group in your replies. I certainly don't have all the answers. 


:-)
Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

On Wed, Nov 1, 2017 at 8:50 AM, Vassilena Treneva <tre...@gmail.com> wrote:
​Hi Ann,

Okay, I adjusted the props and now I get:

Executing command:
SonarQube.Scanner.MSBuild.exe end  /d:"sonar.login=bgqatest" /d:"sonar.password=qatest123"
===============
SonarQube Scanner for MSBuild 3.0.2
Default properties file was found at E:\rel\10.2.0.x\prod\csharp\SonarQube.Analysis.xml
Loading analysis properties from E:\rel\10.2.0.x\prod\csharp\SonarQube.Analysis.xml
Post-processing started.
14:46:27.555  SonarQube analysis could not be completed because the analysis configuration file could not be found: E:\rel\10.2.0.x\prod\csharp\.sonarqube\conf\SonarQubeAnalysisConfig.xml.
14:46:27.558  Post-processing failed. Exit code: 1

I am attaching the full console. Executed commands are printed in the log right after [Executing command] string. 
What is that I am doing wrong?

Thanks a lot for your help.

duncan.po...@sonarsource.com

unread,
Nov 1, 2017, 11:01:28 AM11/1/17
to SonarQube
Hi there.

The end command looks ok.

However, looking at your latest cmd.txt you have a problem with the begin step:


===============
Executing command:
SonarQube.Scanner.MSBuild.exe begin /s:"E:\rel\10.2.0.x/prod/csharp/SonarQube.Analysis.xml" /d:"sonar.login=bgqatest" /d:"sonar.password=qatest123"

===============
SonarQube Scanner for MSBuild 3.0.2
Loading analysis properties from E:\rel\10.2.0.x/prod/csharp/SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
14:39:53.852 14:39:53.849 A required argument is missing: /key:[SonarQube project key]
14:39:53.853 Expecting at least the following command line argument:
- SonarQube project key
When connecting to a SonarQube server earlier than version 6.1, the following command line arguments are also required:
- SonarQube project name
- SonarQube project version

...
 

Check that you have specified the project key (and name and version if appropriate), either on the command line for begin, or in your settings file.

Regards,
Duncan
Ann
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/mtPIPobAefA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Vassilena Treneva

unread,
Nov 1, 2017, 11:04:11 AM11/1/17
to G. Ann Campbell, SonarQube
Hello Everyone,

So, after many different adjustments I still cannot make it work. Full command line output is this one:​
I have enabled debug options - individual commands are printed under Executing command string...

Now I get this:
 
The supplied Code Analysis ErrorLog file is not a valid json file: E:\rel\10.2.0.x\prod\csharp\applications\txpublish\txpublish\bin\Debug\txpublish.exe.RoslynCA.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\txpublish\txpublish\bin\Debug\txpublish.exe.RoslynCA_fixed.json
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: key

The supplied Code Analysis ErrorLog file is not a valid json file: E:\rel\10.2.0.x\prod\csharp\applications\txpushq\txpushq\bin\Debug\txpushq.exe.RoslynCA.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\txpushq\txpushq\bin\Debug\txpushq.exe.RoslynCA_fixed.json
The supplied Code Analysis ErrorLog file is not a valid json file: E:\rel\10.2.0.x\prod\csharp\applications\XMLExport\bin\Debug\XMLExport.exe.RoslynCA.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\XMLExport\bin\Debug\XMLExport.exe.RoslynCA_fixed.json
The supplied Code Analysis ErrorLog file is not a valid json file: E:\rel\10.2.0.x\prod\csharp\applications\XMLImport\bin\Debug\XMLImport.exe.RoslynCA.json
   at SonarQube.Common.ListPropertiesProvider.TryGetProperty(String key, Property& property)
   at SonarQube.Common.AggregatePropertiesProvider.TryGetProperty(String key, Property& property)
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\XMLImport\bin\Debug\XMLImport.exe.RoslynCA_fixed.json
   at SonarQube.Common.AggregatePropertiesProvider.GetAllProperties()
   at SonarScanner.Shim.PropertiesFileGenerator.GetAnalysisProperties(AnalysisConfig config)
   at SonarScanner.Shim.PropertiesFileGenerator.GenerateFile(AnalysisConfig config, ILogger logger, IRoslynV1SarifFixer fixer)
   at SonarScanner.Shim.SonarScannerWrapper.Execute(AnalysisConfig config, IEnumerable`1 userCmdLineArguments, ILogger logger)
   at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.InvokeSonarScanner(IAnalysisPropertyProvider cmdLineArgs, AnalysisConfig config)
   at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute(String[] args, AnalysisConfig config, ITeamBuildSettings settings)
   at SonarQube.Bootstrapper.BootstrapperClass.PostProcess()
   at SonarQube.Bootstrapper.BootstrapperClass.Execute()
   at SonarQube.Bootstrapper.Program.Execute(String[] args, ILogger logger)
   at SonarQube.Bootstrapper.Program.Main(String[] args)

Any thoughts are welcome!

duncan.po...@sonarsource.com

unread,
Nov 1, 2017, 11:52:00 AM11/1/17
to SonarQube
Well, that's progress.

The begin step is working, the build is working and completes successfully, and the end step is configured correctly.

The warnings in the log about invalid json files like the following one are not the reason the end step if failing.
The supplied Code Analysis ErrorLog file is not a valid json file: E:\rel\10.2.0.x\prod\csharp\applications\txpublish\txpublish\bin\Debug\txpublish.exe.RoslynCA.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: E:\rel\10.2.0.x\prod\csharp\applications\txpublish\txpublish\bin\Debug\txpublish.exe.RoslynCA_fixed.json 
It's just means you're using an old version of VS2015 that has a bug in it which the scanner tries to work around.


Check your settings file - do you have any properties defined in it with the emtpy/whitespace-only property names? 
e.g. <Property Name="">false</Property>
That causes a similar failure on my machine.

As an aside, your /k:"com.softwareag:num"  parameter has a colon in it but your /n:"com.softwareag.num" parameter doesn't. This won't affect the analysis - just mentioning it in case you intended them to be the same.

Regards,
Duncan
Ann
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/mtPIPobAefA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Vassilena Treneva

unread,
Nov 2, 2017, 3:38:54 AM11/2/17
to duncan.po...@sonarsource.com, SonarQube
Hey Duncan,

Many thanks for your help. 

I guess the settings file would be the one created (not by me, but by the scanner) under <csharp.sonar.projectBaseDir>\.sonarqube\conf\SonarQubeAnalysisConfig.xml?

I was not able to find such a property in that file. I am attaching it here (SonarQubeAnalysisConfig.xml).

The original file that I use contains less properties and they look fine as well. Attached here as well (SonarQube.Analysis.xml).

Perhaps I am missing something? 


To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/16ab3a35-d82b-46a6-9479-73c2b0e06a24%40googlegroups.com.
SonarQube.Analysis.xml
SonarQubeAnalysisConfig.xml

duncan.po...@sonarsource.com

unread,
Nov 2, 2017, 9:38:56 AM11/2/17
to SonarQube
Hi Vassilena,

I think the problem is with your hand-edited SonarQube.Analysis.xml file.

XML is case-sensitive so the Property Name attribute should have an upper-case "N".
There are a number of properties with "name" instead. Once I changed those, the analysis completed successfully.

I've created a bug to improve the validation and error message: SONARMSRU-347.

Regards,
Duncan

Vassilena Treneva

unread,
Nov 3, 2017, 7:18:58 AM11/3/17
to Duncan Pocklington, SonarQube
​When I kicked off that setup across the pool of VMs we have I get this (same passes well on my local machine):

ERROR: JAVA_HOME not found in your environment, and no Java executable present in the PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation, or add "java.exe" to the PATH

I do have java.exe on PATH but I do not have JAVA_HOME defined on the virtual machine. I guess it needs JAVA_HOME?

Ant framework knows that java.home=C\:\\Program Files\\Java\\jdk1.8.0_31\\jre so my question is - how do I tell the scanner where the jre is? In the xml file or as msbuild switch to one of the commands?

Attaching full output in cmd.txt



On Fri, Nov 3, 2017 at 12:23 PM, Duncan Pocklington <duncan.po...@sonarsource.com> wrote:
Hi Vassilena,

Great, glad to hear it worked. Thanks for persevering!

Multi-projects including C#: I don't know if this is currently possible but I suspect not. The best thing to do is probably to ask the question in a new topic in the SonarQube Google group - that's probably the simplest way to make sure the people who will be able to give a definitive answer will see it.

Regards,
Duncan




On Thu, Nov 2, 2017 at 3:31 PM Vassilena Treneva <tre...@gmail.com> wrote:
Hey Duncan,

Many many thanks! Once I fixed this (the xml gets created by a template in ant) - the execution completed. I am still in preview mode, so will see published results later in the day...

One side question - the project that I have is a multi-language one (java, cpp and c#) and all the publications to the server (for java and cpp) are done using ant jacoco tasks, while this msbuild csharp runner does the publication internally and I have no control in ant on this process.

So I wonder - is there a way to make this work in a multi-language project where the publication happens once per the entire project and the project on sonar side is a single one? 


To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/ced69901-75b7-447e-880a-2341231d25ea%40googlegroups.com.

duncan.po...@sonarsource.com

unread,
Nov 3, 2017, 9:04:41 AM11/3/17
to SonarQube
The scanner works out where the jre is using the PATH or the JAVA_HOME environment variable. You don't need pass it explicitly.

The PATH should include the folder containing java.exe e.g. C:\Program Files\Java\jre1.8.0_144\bin, rather than the root folder for the jre.

I don't have JAVA_HOME set as an environment variable on my machine, but it looks like if you do set it then it should point to the root jre folder i.e. C:\Program Files\Java\jre1.8.0_144.

Regards,
Duncan

Vassilena Treneva

unread,
Nov 3, 2017, 5:17:40 PM11/3/17
to Duncan Pocklington, SonarQube
Is there some way to pass location to java.exe instead of relying on what is on PATH? 

My problem is that I have pools of VMs and many of them simply lack that setting, so I was hoping to be able to pass this as a property somehow...?


To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/519aadca-2442-4d42-83df-27cedcab1def%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages