SCM provider autodetection failed for Azure Devops pipeline

ALM: Azure Devops
CI: Asure Devops
Scanner command used:

- task: SonarCloudPrepare@1
  displayName: 'Analysis: Prepare SonarCloud Analysis'
  inputs:
    sonarCloud: ${{parameters.sonarCloud}}
    organization: ${{parameters.sonarCloud.organization}}
    projectKey: ${{parameters.sonarCloud.projectKey}}
    projectName: ${{parameters.sonarCloud.projectName}}
    extraProperties: ${{parameters.sonarCloud.extraProperties}}

Langugages of repository: C#, Typescript, SCSS, HTML, SQL

and after build / tests

- task: SonarCloudAnalyze@1
    displayName: 'Run SonarCloud analysis'
- task: SonarCloudPublish@1
    displayName: 'Publish results on build summary'
    inputs:
      pollingTimeoutSec: '300'

Warning when running analysis as below:
SCM provider autodetection failed. Please use “sonar.scm.provider” to define SCM of your project, or disable the SCM Sensor in the project settings.

We have seen where code issues are incorrectly being flagged as originating in the branch being analysed when they are pre-existing issues in the code base. We are doing a full git clone - not shallow.

I have tried setting the SCM provider manually in the project’s general settings as below

As soon as I do that the next analysis had an error saying ‘Not inside a Git work tree’.

##[error]ERROR: Error during SonarScanner execution
ERROR: Error during SonarScanner execution
##[error]ERROR: Not inside a Git work tree: /
ERROR:
ERROR: Not inside a Git work tree: /
ERROR: 
##[error]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]10:34:18.703  Post-processing failed. Exit code: 1
10:34:18.703  Post-processing failed. Exit code: 1
##[error]The process '/azp/_work/_tool/dotnet/dotnet' failed with exit code 1

Hey there.

This looks similar to this thread:

Can you run an ls -la immediately before SonarQubeAnalyze to see if there is a .git folder? And, could you also run git --version to return the Git version info?

Ran it again with the above. We do have a .git directory and the git version is coming back in the Azure DevOps pipeline as 2.34.1.

image

image

Still see the warning about SCM in the Sonar run though.

In the hope that the forum may be useful to some - the issue here was that the analysis was being performed at the wrong level when source code was checked out into the Azure DevOps pipeline.

The issue was seen in the pull-request where the path prefix was wrong (not sure why as it was working previously):

By setting sonar.projectBaseDir on the SonarCloudPrepare task to the Azure DevOps pipeline variable Build.SourcesDirectory the warning in the analysis run went away and the problem of incorrect issues being reported went too (I believe that is due to the SCM identification now working correctly).

- task: SonarCloudPrepare@1
    displayName: 'Analysis: Prepare SonarCloud Analysis'
    inputs:
      sonarCloud: ${{parameters.sonarCloud.cloud}}
      organization: ${{parameters.sonarCloud.organization}}
      projectKey: ${{parameters.sonarCloud.projectKey}}
      projectName: ${{parameters.sonarCloud.projectName}}
      extraProperties: |
        ${{parameters.sonarCloud.extraProperties}}
        **sonar.projectBaseDir=$(Build.SourcesDirectory)**
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.