SonarQube Build Duration increased from 10 minutes to 5 hours

Hello,

We’ve tried SonarQube scans on one of our projects. Once we’ve implemented SonarQube steps into the build pipeline, the whole build process took almost 5 hours - instead of originaly observed 10 minutes. I’ve attached the log part where there is gap that lasts for more than 3 hours. SonarQube Version is 7.4.SQ.txt (2.7 KB)

Can you please advise any suggestion how can we make this scan to perform faster?

Kind Regards,
Daniel Krivda

Hi @Danielson,

Does the build eventually complete successfully, and are the analysis results eventually uploaded to SonarQube successfully?

As a rule of thumb, we’ve expect the build time to approximately double with analysis enabled, so even going from ten minutes to an hour would be very unusual. However, there are corner cases where a particular analysis rule performs very slowly on a specific file (e.g. this bug).

My guess is that is what is happening here - most projects will be analysed ok, but there will be one or two files that aren’t being handled correctly that are causing the vast bulk of the increase. If that’s the case, then the workaround is to exclude those files from the analysis.

To confirm whether this is the case, I suggest you try passing the following properties to MSBuild:
/p:reportanalyzer=true /v:d
… and then search the logs for Total analyzer execution time: to see if analysis is particularly slow for one or more projects (see the post Help Figuring Out .NET Project Scan Taking Significantly Longer for more info).

It looks from your build log that your solution is only building the *.wixproj, which in turn is using PowerShell to trigger a separate MSBuild. I think the problem is occurring in that “inner” build so that is one you’ll need to pass the additional parameters to.

1 Like

Thank you very much with your suggestion. I will try it out.

One idea that popped up - We don’t have the ‘SonarScanner for MSBuild’ installed on the agent build machine. Can this have an impact on the overall scan duration?

I’ve checked the log. There is one file that has scan time 6757 seconds, that is almost 2 hours. But rest of the files have around 15 minutes accumulated. How can we find the remaining hours?

Here are

2019-12-02T15:47:21.5356856Z 6757.946 100 SonarAnalyzer.CSharp, Version=7.15.0.0, Culture=neutral, PublicKeyToken=
2019-12-02T15:47:21.5356933Z 6745.751 99 SonarAnalyzer.Rules.CSharp.UnusedPrivateMember

You could try enable the MSBuild binary logging by passing /bl to MSBuild and use the binary log viewer to work out which projects/targets/tasks are taking the time.

Hello Duncan, Thank you for the tips.

I’ve checked it and there is on project task - Build / CoreBuild / PreBuildEvent / Task Exec that took additional 2:49:39 (Capture.png). Though, there is no correlation to SonarQube, at least I don’t see it at first glance. When I reconfigured the build without the SonarQube tasks (Capture2.png), the duration took less than a minute. Please see attached screenshots.

The affected project is .wixproj file


Hi @Danielson,

That looks like the build log for the “outer” build step. You need to look at the build log for the “inner” build step i.e. the invocation of MSBuild that is launched by the PowerShell script.