Version of SonarQube:
Community Edition Version 7.6 (build 21501)
Version of Sonar-Scanner-MSBuild:
sonar-scanner-msbuild-4.6.2.2108-net46
Build environment:
Windows 10
MSBuild.exe from Visual Studio 2017
Version of MSBuild:
Microsoft ® Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright © Microsoft Corporation. All rights reserved.
I am using the Sonar Scanner for MSBuild to analyze a large .Net project that includes C# and C++.
I am using the Community Edition, so it is ignoring the C++ code and only anlyzing C#, which is fine.
The build is launched from Jenkins, but does not use the Jenkins plugin because the existing legacy build scripts have the calls to MSBuild.exe buried a few layers deep in batch files. So I put the sonar-scanner-msbuild.exe “begin” and “end” calls in the batch file that invokes MSBuild.exe.
The build executes in a ClearCase dynamic view, which is mounted under the M: drive. I have sonar.scm.disabled=true because SQ does not need to interact with the SCM system.
The command line for the sonar-scanner-msbuild “begin” command is this:
“C:\sonar-scanner-msbuild-4.6.2.2108-net46\SonarScanner.MSBuild.exe” begin /k:“ABCD-EF” /d:sonar.verbose=true /d:sonar.scm.disabled=true /d:sonar.host.url=“http://mysonarserver:9000/” /d:sonar.sources=All_ABCD
The “All_ABCD” directory is the directory that contains the master SLN file.
The analysis seems to run with no issues, right up until the point where it is trying to assemble the analysis data into a complete report for upload to the server. Then it throws this exception:
13:15:53.621 INFO: Importing 32 Roslyn reports
13:15:53.855 INFO: ------------------------------------------------------------------------
13:15:53.855 INFO: EXECUTION FAILURE
13:15:53.855 INFO: ------------------------------------------------------------------------
13:15:53.855 INFO: Total time: 1:02.414s
13:15:53.944 INFO: Final Memory: 17M/298M
13:15:53.945 INFO: ------------------------------------------------------------------------
13:15:53.945 ERROR: Error during SonarQube Scanner execution
org.sonar.core.util.ContextException: Unable to write issue | file=M:\jenkins_view\ABCD-EF\01_Build\Automated_Build\Jenkins.sonarqube\out.sonar\scanner-report\issues-470.pb
at org.sonar.core.util.ContextException.of(ContextException.java:125)
at org.sonar.scanner.protocol.output.ScannerReportWriter.appendComponentIssue(ScannerReportWriter.java:87)
at org.sonar.scanner.issue.IssuePublisher.write(IssuePublisher.java:188)
at org.sonar.scanner.issue.IssuePublisher.initAndAddIssue(IssuePublisher.java:74)
at org.sonar.scanner.sensor.DefaultSensorStorage.store(DefaultSensorStorage.java:391)
at org.sonar.api.batch.sensor.issue.internal.DefaultIssue.doSave(DefaultIssue.java:90)
at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:45)
at org.sonarsource.dotnet.shared.plugins.SarifParserCallbackImpl.createIssue(SarifParserCallbackImpl.java:202)
at org.sonarsource.dotnet.shared.plugins.SarifParserCallbackImpl.onIssue(SarifParserCallbackImpl.java:157)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleResultFileElement(SarifParser10.java:167)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocationsElement(SarifParser10.java:139)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssue(SarifParser10.java:108)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssues(SarifParser10.java:96)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:66)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:40)
at org.sonarsource.dotnet.shared.plugins.RoslynDataImporter.importRoslynReports(RoslynDataImporter.java:54)
at org.sonarsource.dotnet.shared.plugins.DotNetSensor.executeInternal(DotNetSensor.java:105)
at org.sonarsource.dotnet.shared.plugins.DotNetSensor.execute(DotNetSensor.java:73)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:408)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:403)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:360)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.io.IOException: The parameter is incorrect
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at java.io.FilterOutputStream.close(Unknown Source)
at org.sonar.scanner.protocol.output.ScannerReportWriter.appendComponentIssue(ScannerReportWriter.java:86)
… 44 more
Process returned exit code 1
The SonarQube Scanner did not complete successfully
13:15:54.061 Post-processing failed. Exit code: 1
The file mentioned in the exception message (issues-470.pb) exists, but is zero bytes.
There are three “issues-xxx.pb” files in that directory, and all of them are zero bytes.
There are several hundred “symbols-xxx.pb” files in that directory, with sizes ranging from 1kb to 12kb.
Based on the “java.io.IOException: The parmeter is incorrect” message, I thought it might be an issue with file encoding. I have tried a few different values for sonar.sourceEncoding, including utf-8 and Windows-1252, and that does not change the behavior.
I also ran with sonar.scanner.dumpToFile, and the exception does not occur, because the dry-run behavior of this parameter means that it never tries to assemble the report.