Need sonarqube support on below intermittent Jenkins build failure at sonar scanner stage

Hi Team,
Im from Devops support ,we do dotnet build and scan for our application on jenkins build agent server.the build server has capabilities of running multiple build in parallel ,the issue is with below error ,the build is failing due to below error intermittently but it works fine when we retry . its frustrating that developer reporting same issue again and again with Devops. so we need to know the possible reason for this error. I did go through your community page already on this issue but unable to get the exact fix to be applied.
Could you please help with permanent solution on this pls?

[2023-01-13T10:51:40.024Z] D:\jenkins\workspace\ines_FIRM_EMEA_Common.UI_release>"C:\Program Files\dotnet\dotnet.exe" sonarscanner end 
[2023-01-13T10:51:40.285Z] SonarScanner for MSBuild 5.0.4
[2023-01-13T10:51:40.285Z] Using the .NET Core version of the Scanner for MSBuild
[2023-01-13T10:51:40.285Z] Post-processing started.
[2023-01-13T10:51:40.543Z] 10:51:40.36  The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
[2023-01-13T10:51:40.543Z] Possible causes:
[2023-01-13T10:51:40.543Z]   1. The project has not been built - the project must be built in between the begin and end steps
[2023-01-13T10:51:40.543Z]   2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.

[2023-01-13T10:51:40.543Z]   3. The begin, build and end steps have not all been launched from the same folder
[2023-01-13T10:51:40.543Z]   4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
[2023-01-13T10:51:40.543Z] 10:51:40.361  Generation of the sonar-properties file failed. Unable to complete the analysis.
[2023-01-13T10:51:40.544Z] 10:51:40.366  Post-processing failed. Exit code: 1
script returned exit code 1

A few questions to help you:

  • What are you trying to accomplish? To find the root cause of the issue occurring.
  • Why does this matter to you? Its failing the jenkins build.
  • How would that look in SonarQube? Alternatives? Nil
  • How would we know it works well? retry works fine.
  • Why should it be a priority now? Its often failing with that error and goes away when we retry.

Make sure to check out our product roadmap as well, to see if your need is already being considered.

Hi,

Since this is happening intermittently I need to ask whether you have multiple build agents. I would guess that you have a lower-than-acceptable version of MSBuild installed on one or more of them.

 
Ann

Hi Ann, No no we use only one windows agent for msbuild and dotnet build through our CICD pipeline.
On the same build agent only it fails and get successful intermittent ly.
Here we are using donet.exe for build and scan.

C:\Program Files\dotnet\dotnet.exe" sonarscanner end

Our build agent is running with dotnet core 6 version whereas their source code is built with dotnet core 3.1 version. Would that be creating issue here? Dotnet core 6 should be backward compatible right it should not create any issues i believe

Hi,

What about the begin command and the build? Are you building before you try to run analysis?

Per the docs:

The Sonar Scanner for .NET requires your project to be built with MSBuild 14.0.

 
Ann

Hello Ann,
I have shared all the commands been run from begin to end below. the one got failed today also has been attached. I need some solid fix for this. please help advise. developers are getting frustrated due to this error occurrence.

Begin Command:- **"C:\Program Files\dotnet\dotnet.exe" sonarscanner begin /k:Test-Project-renamed.develop /n:Test-Project-renamed.develop /v:1.6.1 /d:sonar.cs.vstest.reportsPaths=TestResults\*.trx /d:sonar.cs.vscoveragexml.reportsPaths=TestResults\DotnetCoverage.coveragexml /d:sonar.nodejs.executable="D:\jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\nodejs\node.exe"**

Build command:- **"C:\Program Files\dotnet\dotnet.exe" publish --no-restore -c Release -o "D:\jenkins\workspace\Test-Project-renamed_develop\UI\"**

UnitTest command:- **dotnet test --no-restore -c Release --collect "Code Coverage" --logger trx --results-directory TestResults**

Coverage conversion command:- **if exist "D:\jenkins\workspace\Test-Project-renamed\UI\CodeCoverage" rd /S /Q "D:\jenkins\workspace\Test-Project-renamed\UI\CodeCoverage"**

End Command:- **D:\jenkins\workspace\Test-Project-renamed>"C:\Program Files\dotnet\dotnet.exe" sonarscanner end** 

[2023-02-09T13:41:36.949Z] SonarScanner for MSBuild 5.0.4
[2023-02-09T13:41:36.949Z] Using the .NET Core version of the Scanner for MSBuild
[2023-02-09T13:41:36.949Z] Post-processing started.
[2023-02-09T13:41:36.949Z] 13:41:36.872  The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
[2023-02-09T13:41:36.949Z] Possible causes:

[2023-02-09T13:41:36.949Z]   1. The project has not been built - the project must be built in between the begin and end steps
[2023-02-09T13:41:36.949Z]   2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.

[2023-02-09T13:41:36.949Z]   3. The begin, build and end steps have not all been launched from the same folder

[2023-02-09T13:41:36.949Z]   4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
[2023-02-09T13:41:36.949Z] 13:41:36.873  Generation of the sonar-properties file failed. Unable to complete the analysis.
[2023-02-09T13:41:36.949Z] 13:41:36.879  Post-processing failed. Exit code: 1
script returned exit code 1

Hi,

The error message lists 4 possible causes

Looking at #1, you did a publish in between the begin and end steps. The docs indicate a Rebuild or build should be used. A quick search sends me to SO, which says:

dotnet build - Builds a project and all of its dependencies.

dotnet publish - Packs the application and its dependencies into a folder for deployment to a hosting system. (PS - this also builds the application before packing)

I’m certainly not a .NET expert, but I guess that if the binaries are already present, publish doesn’t re-build them, which would explain the intermittency of your failure.

 
HTH,
Ann

Hi Ann, “dotnet publish” command implicitly does the same thing as dotnet build ,so not required to do dotnet build separately,we do “dotnet restore” in the beginning to restore dependencies already.you know we use the same command since last few years without any issues . its a shared pipeline and will be used by multiple projects and the issue is reported only from 1 particular project very often .so Im damn sure no issues with the command being passed . we need to understand the issue from some other perspective which im not able to get it . I have tried lot of options to stop that issue but no luck yet . hence seeking your help. please help check if any one else have come across such issues in your issue history and advise.

Hi,

You’ve fully demonstrated I’m out of my depth. :sweat_smile:

I’ve called for reinforcements.

 
Ann

Hello @IlaiyaRaja

Can you please try to do a dotnet build --no-incremental and afterwards a dotnet publish --no-build to check if it works that way? And from that point, we can investigate further.

All the best,
Čaba