System.IO.InvalidDataException: End of Central Directory record could not be found

I’m trying to configure SonarQube Community EditionVersion 7.2.1 (build 14109) with TFS 2015 update 4. I’m doing this in my lab. The SonarQube server is a Bitnami VM. TFS is on another VM. I downloaded version 3.1 of the SonarQube extension and added it to TFS.
I created a SonarQube endpoint and added a Name, URL, and the token and clicked OK. I then navigated to the build definition in TFS and add two build steps, SonarQube for MSBuild - Begin Analysis and SonarQube for MSBuild - End Analysis. When I try to edit the SonarQube Endpoint in the step definition, There is nothing in the drop-down box. It remains yellow and I can’t add it.

I found an article online that said I could create it as a Generic type. I was able to add it with the following entries.
I called it generic, gave it the url of http://192.168.1.103 username was blank and password/token was my sonarqube token.

I no went back to the build definition to add the sonarqube steps. This time the Endpoint drop-down had the choice of generic which is what I called the endpoint. For Project Key and Project Name I called them msbuild-example. I then save the definition and got no errors.

I get the following error during the build:
Starting task: Fetch the Quality Profile from SonarQube


Executing the powershell script: C:\Agent\tasks\SonarQubePreBuild\1.0.35\SonarQubePreBuild.ps1
SonarQube Scanner for MSBuild 1.1
Default properties file was not found at C:\Agent\tasks\SonarQubePreBuild\1.0.35\MSBuild.SonarQube.Runner-1.1\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories…
Checking for updates…
Could not find a file on the SonarQube server. Url: http://192.168.1.103/static/csharp/SonarQube.MSBuild.Runner.Implementation.zip
Failed to update the SonarQube Scanner for MSBuild binaries. Check the server url, verify that the C# plugin is correctly installed on the SonarQube server and that the SonarQube server has been restarted.
Pre-processing failed. Exit code: 1
Unexpected exit code received from batch file: 1


Finishing task: SonarQubePreBuild

Any thoughts

Patrick,

First red flag is the version of SonarQube Scanner for MsBuild being used. That’s a very old version. v3.1.0 of the TFS extension shipped with v4.0 of the scanner.

Do you happen to have tasks available that are named the same as the ones that you are using but appended with “(New)”?

Long story short: I believe TFS shipped with SonarQube tasks at one point, but those are now quite old, deprecated, and are marked as such in later versions of TFS (if not removed entirely by now). The old, built in tasks used a generic endpoint, while the new ones use an endpoint of type “SonarQube”. Since you were able to create the latter, I have faith the extension was installed correctly on your TFS instance.

Colin

Thank you for you help. I checked our on-site TFS system and I see that when adding new tasks to a build definition there are 2. SonarQube for MSBuild - Begin Analysis and SonarQube for MSBuild - End Analysis. This system does not have the new TFS extension installed. I used those tasks in my testing. So my first question would be, is there a way to remove those from the available choices?

I will go back to my off-site test environment and add the try again, not using the steps above.
I will update you later.

Pat

BAM — I removed the Endpoints that I originally created, and created a new one using the SonarQube New Service Endpoint definition. Then I added the correct Tasks to the build definition and now it works. Thank you so much.

I’m having the same issue, my server details: * Community Edition Version 7.3 (build 15553):

18:03:27 + dotnet sonarscanner begin /d:sonar.host.url=SONAR_URL /d:sonar.login=**** /k:PROJECTKEY
18:03:28 SonarScanner for MSBuild 4.10
18:03:28 Using the .NET Core version of the Scanner for MSBuild
18:03:28 Pre-processing started.
18:03:28 Preparing working directories…
18:03:28 16:03:28.074 Updating build integration targets…
18:03:28 16:03:28.105 Fetching analysis configuration settings…
18:03:29 16:03:29.016 Provisioning analyzer assemblies for cs…
18:03:29 16:03:29.017 Installing required Roslyn analyzers…
18:03:29 Unhandled exception. System.IO.InvalidDataException: End of Central Directory record could not be found.
18:03:29 at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
18:03:29 at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)
18:03:29 at System.IO.Compression.ZipArchive…ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding)
18:03:29 at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
18:03:29 at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding, Boolean overwriteFiles)
18:03:29 at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName)
18:03:29 at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.FetchResourceFromServer(Plugin plugin, String targetDir)
18:03:29 at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.GetPluginResourceFiles(Plugin plugin)
18:03:29 at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.InstallAssemblies(IEnumerable1 plugins) 18:03:29 at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.FetchAnalyzerPlugins(String language, IEnumerable1 activeRules)
18:03:29 at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.SetupAnalyzer(TeamBuildSettings teamBuildSettings, IAnalysisPropertyProvider sonarProperties, IEnumerable1 activeRules, IEnumerable1 inactiveRules, String language)
18:03:29 at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.FetchArgumentsAndRulesets(ISonarQubeServer server, ProcessedArgs args, TeamBuildSettings settings, IDictionary2& serverSettings, List1& analyzersSettings)
18:03:29 at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
18:03:29 at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute(String args)
18:03:29 at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
18:03:29 at SonarScanner.MSBuild.BootstrapperClass.Execute()
18:03:29 at SonarScanner.MSBuild.Program.Execute(String args, ILogger logger)
18:03:29 at SonarScanner.MSBuild.Program.Execute(String args, Boolean showDeprecatedWarning)
18:03:29 at SonarScanner.MSBuild.Program.Main(String args)