SonaQube "Run Code Analysis" Task in Azure CI Build fails randomly with Error "The SonarQube MSBuild integration failed:"

Azure CI Build fails due to “Run Code Analysis” Task throw below error randomly. However, it will succeed on the next run.

##[error]The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.

Please do the needful. Since the error is random and not frequent it is difficult to identify the root cause.

Hello,

Could you please detail how you are integrating with the scanner? For example, please provide the pipeline YAML.

Also, could you please give us verbose logs? Please give us the verbose output of the command (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of thje BEGIN and END steps).

And please answer to the following question : what is the version of SonarQube that you are using?

Thanks @Andrei_Epure, for your reply.

I am using SonarQube Community Edition Version 8.4.1 (build 35646).
We have integrated SonarQube in our Azure CI build pipeline. We created a service connection b/w DevOps and SonarQube instance.

This issue very random and very difficult to reproduce, it is occurring with any of the pipeline randomly, its occurrence ratio could be around 1 in 50 build runs. Attaching the YAML code of our Azure CI pipeline.

pool:
  name: Default
  demands:
  - msbuild
  - visualstudio
  - java

#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘Parameters.ArtifactName’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore Inventory Service'
  inputs:
    restoreSolution: '$(Parameters.solution)'
    vstsFeed: '/a0f4eedf-9590-47c0-b8ab-b70e83621d94'
    includeNuGetOrg: false
    restoreDirectory: '..\..\packages\'

- task: sonarsource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@4
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: SonarQubeProdConnection
    projectKey: InventoryService
    projectName: 'Inventory Service'
    extraProperties: |
     # Additional properties that will be passed to the scanner, 
     # Put one key=value per line, example:
     sonar.inclusions=SRC/TCore.Sal/src/Services/TCore.Sal.Services.Inventory.Service/**,SRC/TCore.Sal/src/Services/TCore.Sal.Services.Inventory/**,SRC/TCore.Sal/src/Services/TCore.Sal.Services.Inventory.Contracts/**,/SRC/TCore.Sal/src/Services/TCore.Sal.Services.Inventory.Repository/**

- task: VSBuild@1
  displayName: 'Build Inventory Service'
  inputs:
    solution: '$(Parameters.solution)'
    vsVersion: 15.0
    msbuildArgs: '/p:OutDir="p" /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true

- task: VisualStudioTestPlatformInstaller@1
  displayName: 'Visual Studio Test Platform Installer'
  inputs:
    packageFeedSelector: customFeed
    customFeed: 'https://tfs/SalProjectsCollection/_packaging/TransGet/nuget/v3/index.json'
    password: annwkmxun4mbsyanrq3zp4j4kpt7s4k3xc6dru3pciinuhxyuara

- task: VSTest@2
  displayName: 'Automated Unit Test'
  inputs:
    vsTestVersion: toolsInstaller
    runSettingsFile: 'SRC/TCore.Sal.Services Solutions/TCore.Sal.Services.Inventory.Service/test.runsettings'
    codeCoverageEnabled: false
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    diagnosticsEnabled: true

- task: sonarsource.sonarqube.6D01813A-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@4
  displayName: 'Run Code Analysis'

- task: sonarsource.sonarqube.291ed61f-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@4
  displayName: 'Publish Quality Gate Result'

- task: SimondeLang.sonar-buildbreaker.sonar-buildbreaker.sonar-buildbreaker@8
  displayName: 'Break build on quality gate failure'
  inputs:
    SonarQube: SonarQubeProdConnection

- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
    PublishSymbols: false
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: 'SRC\TCore.Sal\src\Services\TCore.Sal.Services.Inventory.Service\p\_PublishedWebsites\TCore.Sal.Services.Inventory.Service'
    ArtifactName: '$(Parameters.ArtifactName)'
  condition: succeededOrFailed()


Let me know if it is sufficient for your analaysis. We usually don’t execute any commands, the scan happens through the build pipeline and Azure DevOps and SonarQube hosted in different servers, I am not sure where exactly you want to run the verbose command.

To get the verbose logs you need to add sonar.verbose=true to the extraProperties of SonarQubePrepare. However, if this happens 1 out of 50 builds, it’s hard to get the verbose logs (as the verbose logs will slow your build time - it’s useful if the issue is reproducible because you can turn it on and then off, but if it doesn’t reproduce… you need to keep verbose logs on until it reproduces, and give the logs of a successful build and of a failed build so that we can compare).

In any case, SQ 8.4 isn’t supported anymore. You either have to update to the latest, or use the Long Term Support (LTS) version - see details on Download | SonarQube

If this reproduces with a supported version of SonarQube, please let us know and share the logs with us.

Thanks,
Andrei