I have been trying to configure SonarQube for performing static code analysis for my projects, however have been encountering multiple issues.
Last week I documented the errors I received while trying to configure the SQL Server Database — SonarQube 6.5 – Issues while configuring SQL Server Database
I am using SonarQube 6.5 version. Once the SonarQube Server was setup and SQL Database was configured, the next step for me was to integrate SonarQube with the TFS Build Process and Define a Quality Gate and fail the build in case of quality gate failures.
I followed the SonarQube documentation and like always it did not just magically started working. I bumped into multiple error messages and issues, hence thought of documenting the same so that if you bump into the same issue, it will help you save time in troubleshooting and fixing the issue.
Looking at the SonarQube Documentation, there are 2 major things which needs to be done for the TFS integration —
- Add a SonarQube Service endpoint
- Enable the SonarQube analysis in the build definition
From Team Foundation Server 2015 or Visual Studio Team Services
Problem Statement –
I followed the above documentation and added the SonarQube – Begin Analysis and End Analysis tasks to my TFS Build definition. I have my SonarQube server up and running. I added a SonarQube Service endpoint and associated it while configuring the SonarQube Begin analysis task.
However when I trigger the build, it failed throwing the below error – ‘Unhandled Exception: System.IO.InvalidDataException: End of Central Directory record could not be found.‘
Starting: Get sourcesRunning tasksStarting task: Fetch the Quality Profile from SonarQubeExecuting the powershell script: c:\Program Files\TFS2015Agent\tasks\SonarQubePreBuild\1.0.34\SonarQubePreBuild.ps1 SonarQube Scanner for MSBuild 1.1 Default properties file was not found at C:\Program Files\TFS2015Agent\tasks\SonarQubePreBuild\1.0.34\MSBuild.SonarQube.Runner-1.1\SonarQube.Analysis.xmlPre-processing started. Preparing working directories… Checking for updates… Unhandled Exception: System.IO.InvalidDataException: End of Central Directory record could not be found. at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory() at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen) at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding) at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding) at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding) at SonarQube.Bootstrapper.BuildAgentUpdater.TryUpdate(String hostUrl, String targetDir, ILogger logger) at SonarQube.Bootstrapper.Program.PreProcess(IBuildAgentUpdater updater, IBootstrapperSettings settings, ILogger logger) at SonarQube.Bootstrapper.Program.Execute(String args, IBuildAgentUpdater updater, ILogger logger) at SonarQube.Bootstrapper.Program.Main(String args)
To resolve the issue, I had to download the latest version of the SonarQube build tasks in TFS from the below link —
The easiest option is to navigate to the Admin TFS Extension Page on the server and use it to download and install the new SonarQube extension.
Once that was done, I triggered the TFS build and was able to get past this error.
The analysis of C# project in SonarQube is really simple since it only requires adding the two SonarQube Scanner for MSBuild tasks to your build definition. However you need to make sure that the latest version of the scanner is installed.
I upgraded the SonarQube version to 6.5 and hence had to make sure that the scanners are updated as well to make it work end to end. While writing this blog on 10/23/2017, you can see that the SonarQube scanner was last updated just a week back.
Categories: C#, SonarQube, Visual Studio
Leave a Reply