I’m trying to run SonarScanner for msbuild inside a docker container.
Inside the docker image, everything seems to work fine, but on the sonarqube server the projects always fails with the following stack trace from the background task:
Error Details: sq-test [Project Analysis]
Error Details
java.lang.IllegalStateException: Fail to extract report AWm0Xnnp6tGu7jYmAU-P from database
at org.sonar.ce.task.projectanalysis.step.ExtractReportStep.execute(ExtractReportStep.java:72)
at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.zip.ZipException: invalid entry size (expected 71872 but got 71630 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:384)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:196)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.sonar.api.internal.apachecommons.io.IOUtils.copyLarge(IOUtils.java:2314)
at org.sonar.api.internal.apachecommons.io.IOUtils.copy(IOUtils.java:2270)
at org.sonar.api.internal.apachecommons.io.IOUtils.copyLarge(IOUtils.java:2291)
at org.sonar.api.internal.apachecommons.io.IOUtils.copy(IOUtils.java:2246)
at org.sonar.api.utils.ZipUtils.copy(ZipUtils.java:167)
at org.sonar.api.utils.ZipUtils.unzipEntry(ZipUtils.java:109)
at org.sonar.api.utils.ZipUtils.unzip(ZipUtils.java:93)
at org.sonar.api.utils.ZipUtils.unzip(ZipUtils.java:62)
at org.sonar.ce.task.projectanalysis.step.ExtractReportStep.execute(ExtractReportStep.java:70)
... 18 more
Running sonarscanner directly on the docker host machine instead works as expected, so there is something strange going on inside the docker container that prevents it from creating a valid zip archive?
Steps to reproduce:
dockerfile:
FROM mcr.microsoft.com/dotnet/framework/sdk:4.7.2
ADD https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/4.6.0.1930/sonar-scanner-msbuild-4.6.0.1930-net46.zip c:/sonarscanner.zip
COPY SonarQube.Analysis.xml.template c:/
SHELL ["powershell.exe", "-Command"]
RUN Expand-Archive ./sonarscanner.zip sonarscanner
ARG SONARQUBE_ANALYSIS_TOKEN
ENV SONARQUBE_ANALYSIS_TOKEN=$SONARQUBE_ANALYSIS_TOKEN
RUN (gc -raw c:/SonarQube.Analysis.xml.template) -replace '{{SONAR_USER_TOKEN}}',"$($env:SONARQUBE_ANALYSIS_TOKEN)" | sc c:/sonarscanner/SonarQube.Analysis.xml
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://javadl.oracle.com/webapps/download/AutoDL?BundleId=236888_42970487e3af4f5aa5bca3f542482c60', 'C:\jre-windows-x64.exe')
RUN powershell start-process -filepath C:\jre-windows-x64.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre,/L,install64.log"
RUN del C:\jre-windows-x64.exe
RUN powershell -Command $ErrorActionPreference = 'Stop' ; \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \
Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-busybox-64-bit.zip' -OutFile 'mingit.zip' -UseBasicParsing ; \
Expand-Archive mingit.zip -DestinationPath c:\mingit ; \
Remove-Item mingit.zip -Force ; \
setx /M PATH $('c:\mingit\cmd;{0}' -f $env:PATH)
RUN [Environment]::SetEnvironmentVariable(\"Path\", \"$($env:Path);C:\sonarscanner;C:\Java\jre\bin\", [EnvironmentVariableTarget]::Machine)
ENTRYPOINT powershell.exe
config template
(named SonarQube.Analysis.xml.template):
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.host.url">http://ldsonarqube01.q.local:9000/</Property>
<Property Name="sonar.login">{{SONAR_USER_TOKEN}}</Property>
</SonarQubeAnalysisProperties>
command to build:
docker build --tag sonar-net472 --build-arg SONARQUBE_ANALYSIS_TOKEN=<valid token from our sonar instance> .
command to start docker
docker run -it sonar-net472
inside docker container
in short:
PS C:\src\SonarQubeTest> where.exe msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
PS C:\src> git clone https://github.com/Zazcallabah/SonarQubeTest.git
PS C:\src\SonarQubeTest> SonarScanner.MSBuild.exe begin /k:sq-test
PS C:\src\SonarQubeTest> msbuild
PS C:\src\SonarQubeTest> SonarScanner.MSBuild.exe end
full output
PS C:\src\SonarQubeTest> where.exe msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
PS C:\src> git clone https://github.com/Zazcallabah/SonarQubeTest.git
Cloning into 'SonarQubeTest'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 8 (delta 0), reused 8 (delta 0), pack-reused 0
Unpacking objects: 100% (8/8), done.
PS C:\src> cd .\SonarQubeTest\
PS C:\src\SonarQubeTest> SonarScanner.MSBuild.exe begin /k:sq-test
SonarScanner for MSBuild 4.6
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
11:20:38.152 Updating build integration targets...
11:20:38.23 Fetching analysis configuration settings...
11:20:38.772 Provisioning analyzer assemblies for cs...
11:20:38.772 Installing required Roslyn analyzers...
11:20:39.388 Provisioning analyzer assemblies for vbnet...
11:20:39.388 Installing required Roslyn analyzers...
11:20:39.466 Pre-processing succeeded.
PS C:\src\SonarQubeTest> msbuild
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 3/25/2019 11:20:44 AM.
Project "C:\src\SonarQubeTest\ClassLibrary1.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\src\SonarQubeTest\ClassLibrary1.sln" (1) is building "C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Debug\ ".
Creating directory "obj\Debug\ ".
CreateProjectSpecificDirs:
Creating directory "C:\src\SonarQubeTest\.sonarqube\conf\0".
CoreCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Pr
ogram Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" /r
eference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System
.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framew
osoft\Framework\.NETFramework\v4.6.1\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize
- /out:obj\Debug\ClassLibrary1.dll /ruleset:C:\src\SonarQubeTest\.sonarqube\conf\SonarQubeRoslyn-cs.ruleset /errorlog:C:\src\SonarQubeTest\ClassLibrary1\bin\Debug\ClassLibrary1.dll.RoslynCA.json /subsystemversion:6.
00 /target:library /warnaserror- /utf8output /deterministic+ /analyzer:C:\Users\ContainerAdministrator\AppData\Local\Temp\.sonarqube\resources\0\Google.Protobuf.dll /analyzer:C:\Users\ContainerAdministrator\AppData\
Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll /analyzer:C:\Users\ContainerAdministrator\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.dll /analyzer:C:\Users\ContainerAdministrator\AppData\Loca
l\Temp\.sonarqube\resources\1\Google.Protobuf.dll /analyzer:C:\Users\ContainerAdministrator\AppData\Local\Temp\.sonarqube\resources\1\SonarAnalyzer.dll /analyzer:C:\Users\ContainerAdministrator\AppData\Local\Temp\.s
onarqube\resources\1\SonarAnalyzer.VisualBasic.dll /additionalfile:C:\src\SonarQubeTest\.sonarqube\conf\cs\SonarLint.xml /additionalfile:C:\src\SonarQubeTest\.sonarqube\conf\0\ProjectOutFolderPath.txt Class1.cs Prop
erties\AssemblyInfo.cs "C:\Users\ContainerAdministrator\AppData\Local\Temp\.NETFramework,Version=v4.6.1.AssemblyAttributes.cs"
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn
Class1.cs(9,18): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj]
Class1.cs(13,19): warning S112: 'System.Exception' should not be thrown by user code. [C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj]
CopyFilesToOutputDirectory:
Copying file from "obj\Debug\ClassLibrary1.dll" to "bin\Debug\ClassLibrary1.dll".
ClassLibrary1 -> C:\src\SonarQubeTest\ClassLibrary1\bin\Debug\ClassLibrary1.dll
Copying file from "obj\Debug\ClassLibrary1.pdb" to "bin\Debug\ClassLibrary1.pdb".
Done Building Project "C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj" (default targets).
Done Building Project "C:\src\SonarQubeTest\ClassLibrary1.sln" (default targets).
Build succeeded.
"C:\src\SonarQubeTest\ClassLibrary1.sln" (default target) (1) ->
"C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj" (default target) (2) ->
(CoreCompile target) ->
Class1.cs(9,18): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj]
Class1.cs(13,19): warning S112: 'System.Exception' should not be thrown by user code. [C:\src\SonarQubeTest\ClassLibrary1\ClassLibrary1.csproj]
2 Warning(s)
0 Error(s)
Time Elapsed 00:00:07.82
PS C:\src\SonarQubeTest> SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.6
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
Calling the SonarQube Scanner...
INFO: Scanner configuration file: C:\sonarscanner\sonar-scanner-3.3.0.1492\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\src\SonarQubeTest\.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_201 Oracle Corporation (64-bit)
INFO: Windows Server 2016 10.0 amd64
INFO: User cache: C:\Users\ContainerAdministrator\.sonar\cache
INFO: SonarQube server 7.7.0
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=94ms
INFO: Server id: 46AF5D23-AWmgxneIx2mybL_sI0bU
INFO: User cache: C:\Users\ContainerAdministrator\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=62ms
INFO: Load/download plugins (done) | time=8390ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=47ms
INFO: Project key: sq-test
INFO: Base dir: C:\src\SonarQubeTest\ClassLibrary1
INFO: Working dir: C:\src\SonarQubeTest\.sonarqube\out\.sonar
INFO: Load project settings for component key: 'sq-test'
INFO: Load project settings for component key: 'sq-test' (done) | time=16ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=109ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=47ms
INFO: Load active rules
INFO: Load active rules (done) | time=547ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Indexing files of module 'ClassLibrary1'
INFO: Base dir: C:\src\SonarQubeTest\ClassLibrary1
INFO: Source paths: Class1.cs, Properties/AssemblyInfo.cs
INFO: Indexing files of module 'sq-test'
INFO: Base dir: C:\src\SonarQubeTest\ClassLibrary1
INFO: 2 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for cs: Sonar way
INFO: ------------- Run sensors on module ClassLibrary1
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=63ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=16ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=16ms
INFO: ------------- Run sensors on module sq-test
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
INFO: Sensor C# [csharp]
INFO: Importing results from 6 proto files in 'C:\src\SonarQubeTest\.sonarqube\out\0\output-cs'
INFO: Importing 1 Roslyn report
INFO: Sensor C# [csharp] (done) | time=203ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=16ms
INFO: SCM provider for this project is: git
INFO: 2 files to be analyzed
INFO: 2/2 files analyzed
INFO: 1 file had no CPD blocks
INFO: Calculating CPD for 1 file
INFO: CPD calculation finished
INFO: Analysis report generated in 110ms, dir size=77 KB
INFO: Analysis report compressed in 31ms, zip size=13 KB
INFO: Analysis report uploaded in 31ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://ldsonarqube01.q.local:9000/dashboard?id=sq-test
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://ldsonarqube01.q.local:9000/api/ce/task?id=AWm0929oe838
INFO: Analysis total time: 4.141 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 20.776s
INFO: Final Memory: 13M/36M
INFO: ------------------------------------------------------------------------
The SonarQube Scanner has finished
11:21:24.516 Post-processing succeeded.
We have a locally hosted installation of SonarQube (Community Edition Version 7.7 (build 23042))
Sonarscanner should be 4.6.0.1930
Can anyone help me figure out what is going wrong here?