SonarQube Azure Pipeline 8.9, extension not working for Pipeline

ENTERPRISE SONARQUBE VERSION: 8.9 LTS

Running SonarQube plugin from Marketplace in Azure Pipelines. Trying to integrate into Pipeline, however, when running, we have following error:

2021-08-24T16:19:21.6662027Z ##[section]Starting: Run Code Analysis
2021-08-24T16:19:21.6825140Z ==============================================================================
2021-08-24T16:19:21.6825429Z Task : Run Code Analysis
2021-08-24T16:19:21.6825704Z Description : Run scanner and upload the results to the SonarQube server.
2021-08-24T16:19:21.6825939Z Version : 4.21.0
2021-08-24T16:19:21.6826120Z Author : sonarsource
2021-08-24T16:19:21.6826610Z Help : Version: 4.21.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

More Information
2021-08-24T16:19:21.6827155Z ==============================================================================
2021-08-24T16:19:21.9772507Z [command]D:\a_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.21.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
2021-08-24T16:19:22.0672786Z SonarScanner for MSBuild 5.2.1
2021-08-24T16:19:22.0683073Z Using the .NET Framework version of the Scanner for MSBuild
2021-08-24T16:19:22.1235841Z Post-processing started.
2021-08-24T16:19:22.2376147Z ##[error]16:19:22.236 The SonarScanner for 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)
    2021-08-24T16:19:22.2379045Z 16:19:22.236 The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
    2021-08-24T16:19:22.2379766Z Possible causes:
    2021-08-24T16:19:22.2380384Z 1. The project has not been built - the project must be built in between the begin and end steps
    2021-08-24T16:19:22.2381717Z 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
    2021-08-24T16:19:22.2382569Z 3. The begin, build and end steps have not all been launched from the same folder
    2021-08-24T16:19:22.2383405Z 4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
    2021-08-24T16:19:22.2384149Z 16:19:22.236 Generation of the sonar-properties file failed. Unable to complete the analysis.
    2021-08-24T16:19:22.2435589Z ##[error]16:19:22.242 Post-processing failed. Exit code: 1
    2021-08-24T16:19:22.2436933Z 16:19:22.242 Post-processing failed. Exit code: 1
    2021-08-24T16:19:22.2574871Z ##[error]The process ‘D:\a_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.21.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe’ failed with exit code 1
    2021-08-24T16:19:22.2643038Z ##[section]Finishing: Run Code Analysis

how do I fix?

Hi @devseceng9

Welcome to SonarSource Community! :sonarsource:

If you have an .NET/C# project, you must use the Sonar Scanner for MSBuild and its 3 steps in the Azure Pipeline. Here’s an example of mine using SonarCloud (it’s basically the same as SonarQube, just use the appropriate SonarQube task equivalents):

trigger:
- master

pool:
  vmImage: 'windows-latest'

steps:
- task: VisualStudioTestPlatformInstaller@1
  inputs:
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'latestPreRelease'
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'sonarcloud'
    organization: 'joetingsanchali'
    scannerMode: 'MSBuild'
    projectKey: 'joetingsanchali_sonar-scanning-someconsoleapp'
    projectName: 'sonar-scanning-someconsoleapp'
    extraProperties: |
      sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)\**\*.trx
      sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)\**\*.coveragexml
      sonar.verbose=true
- task: MSBuild@1
  inputs:
    solution: '**\*.sln'
    msbuildArguments: '-t:Rebuild'
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    codeCoverageEnabled: true
    searchFolder: '$(System.DefaultWorkingDirectory)'
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

The key point is this:

  • Make sure you have the SonarQubePrepare task (this is the equivalent of the BEGIN step)
  • Build your project (make sure to use /t:Rebuild or --no-incremental) (this is your BUILD step)
  • Make sure you have the SonarQubeAnalyze task (this is your END step)
  • Make sure you have the SonarQubePublish task (this is for your quality gate)

Joe