0

I have two .NET solutions, one is in .NET 5 and other is in .NET Classic 4.7.2. Each solution has separate Jenkins build job. Each job also analyze the solution using SonarQube's MSBuild scanner.

I am using SonarQube Server version 8.5
Scanner for .NET 5 sonar-scanner-msbuild-5.1.0.28487-net5.0
Scanner for .NET 4.7.2 sonar-scanner-msbuild-4.10.0.19059-net46

Issue
In Jenkins, When .NET 5 build is running, and at the same time if I execute another .NET Classic build then the latter one fails with the error

C:\Users\jenkinsuser\AppData\Local\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets(62,5): error : The build is configured to run SonarQube analysis but the SonarQube analysis targets could not be located. Project: MyProject.csproj

I think the issue here is both scanners are sharing same location to store targets, so the latter one fails. I think have two options here

1>Is there anyway to run one job at a time in Jenkins without using any third party plugin? In Maven Project Configuration there is # of executors currently set to 3. Will changing this to 1 execute only one job at a time? Are there any side effects changing this value to 1.

2>In Sonar Scanner is there any property I can set on each scanner, so that scanner would use different location for targets

LP13
  • 30,567
  • 53
  • 217
  • 400

1 Answers1

0

Please consider global target installation as described in the documentation:

Concurrent Analyses on the Same Build Machine

Concurrent analyses (i.e. parallel analysis of two solutions on the same build machine using a unique service account) are not supported by default by the Scanner for .NET. You can enable it as follows:

  1. Locate the folder containing the Scanner for .NET
  2. Go in the Targets folder and copy the folder SonarQube.Integration.ImportBefore.targets
  3. Paste it under your build tool global ImportBefore folder (if the folder doesn't exist, create it).
  • For MSBuild, the path is <MSBUILD_INSTALL_DIR>\<Version>\Microsoft.Common.targets\ImportBefore where <MSBUILD_INSTALL_DIR> is:
    • For v14, default path is: C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.Targets\ImportBefore
    • For v15, default path is: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Microsoft.Common.targets\ImportBefore (for VS Community Edition)
    • For v16, default path is: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Microsoft.Common.targets (for VS Enterprise Edition)
  • For dotnet, the path is <DOTNET_SDK_INSTALL_DIR>\15.0\Microsoft.Common.targets\ImportBefore where <DOTNET_SDK_INSTALL_DIR> can be found using the dotnet --info and looking for the Base Path property.

The performance impact of this global installation for projects that aren't analyzed is negligible as this target is only a bootstrapper and will bail out nearly instantaneously when the .sonarqube folder is not found under the folder being built.

raspy
  • 3,995
  • 1
  • 14
  • 18