Does SonarCloud have an impact on build time?

Hi All :slight_smile:
We’re using ADO with Git repositories.
All code is in C#.
We noticed very strange behavior. Same pipelines, the difference between them is that in one we have tasks from SonarCloud in the other not.
The Build task and Unit Test task times are very different to the disadvantage of the one with Sonar. Can SonarCloud and its tasks affect the build time of the application?
image
image

Hi,

When I look at your two screenshots, here’s what I see:

step with without
Initialize job <1s <1s
Pre-job BuildQualityChecks :x: 2s
Checkout 26s 16s
Download 3s 4s
Use .NET Core sdk 4s 4s
Restore NuGet Packages 21s 36s
VisualStudioTestPlatformInstaller 4s :x:
SonarCloudPrepare 50s :x:
Build 11m 14s 2m 6s
Run UnitTests 7m 53s 3m 32s
Run IntegrationTests :x: 20s
Download Databaseupgrade pack… :x: 9s
Run database midgrations :x: 1m 13s
SonarCloudAnalyze 20m 51s :x:
SonarCloudPublish 2m 51s :x:
sonarcloudbuildbreaker 3s :x:

From the lack of “VisualStudioTestPlatformIntaller” in the fast job, (as well as differences in a number of other steps) this looks to me like an apples/oranges comparison and not quite “same pipelines”. Analysis may be having some impact on build time, but to what degree is that also affected by VisualStudioTestPlatformInstaller?

 
Ann

I can agree with you that the pipelines are a little different, but it is the same product and it seems that pre-build tasks should not have any impact on the build time. The computers on which the build goes are the same, so the times should also be the same or close, and here the difference is in the hundreds of percent.
BR
Bartek

Hi,

The difference in the pipelines, particularly VisualStudioTestPlatformInstaller, makes me really wonder if the same build configuration is used in both. I.e. if the difference in the build time isn’t intrinsic. Would it be possible to a real apples-to-apples comparison?

 
Ann

Hi Ann,
We have made the changes you wrote about and this step that raised your concerns is irrelevant. Build with SonarCloud enabled extends the build time.
Maybe some information during the build is sent to SonarCloud servers?

Hi,

Data to SonarCloud is only sent at the end. It’s possible some data is requested, but I think that actually all happens during the ‘Prepare’ step.

I’m going to flag this for more expert eyes.

 
Ann

1 Like

Hello @bartoszrichert,

The SonarCloudPrepare step instruments the msbuild to run our rules during the build. This results in an increase in build time. In your case, the build time increased by factor 6 which is quite high and slightly above what we usually see as an increment.
It is suspicious that the Run UnitTests task also doubles in duration. Our rules only run during build. In case Run UnitTests does no compilation but uses the artifacts from the build step you shouldn’t see this increase.
Can you please run the steps (SonarCloudPrepare, Build, Run UnitTests, SonarCloudPrepareAnalyze, and SonarCloudPreparePublish) with verbose logging and send us the logs?

Best, Martin

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d