Sonarcloud on Azure DevOps with bitbucket source repo "SonarCloud was unable to collect the required information about your projects."

I am getting the error “SonarCloud was unable to collect the required information about your projects.”.

We host our code in BitBucket and use Azure DevOps for our builds.

So I setup the build yaml file like this:

- task: DotNetCoreCLI@2
  displayName: Restore nuget packages
  inputs:
    command: 'restore'
    projects: |
      **/*.csproj
    feedsToUse: 'select'
    vstsFeed: '<feed>'
- task: UseGitVersion@5
  displayName: Set Git Version
  inputs:
    versionSpec: '5.x'
    updateAssemblyInfo: false
- task: DotNetCoreCLI@2
  displayName: Build projects
  inputs:
    command: 'build'
    arguments: '--configuration $(BuildConfiguration) --no-restore /p:Version=$(GitVersion.NuGetVersion) /p:SourceLinkCreate=true /p:PublicRelease=true'
    versioningScheme: byBuildNumber  
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud'
    organization: '<org>'
    scannerMode: 'MSBuild'
    projectKey: '<key>'
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

The build fails on the “SonarCloudAnalyze” task. The Prepare step succeeded.

It gives me 4 possible causes in the error message:

  1. The project has not been built - the project must be built in between the begin and end steps
    As you can see I have a build step before the analyze step, so that should not be a problem. This is an existing build with also a unittest step and that one works, so clearly the solution is build.

  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
    On the build step I can see “Microsoft ® Build Engine version 16.8.3+39993bd9d for .NET”. So I think that should be fine.

  3. The begin, build and end steps have not all been launched from the same folder
    I didn’t set any custom folders for steps, but this is hard to verify. I don’t see any more information in the build about this.

  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
    The project has a solution, but as you can see in the build step, we do build by project? Could that be the problem?

Can someone help me with this issue? I am not sure how I could get more information to figure out what the problem is here. It is a new configuration, so I probably have something misconfigured or am not understanding something, but not sure how proceed debugging this further.

Thank you,
Erik

Hi @eriksteinebach ,

Welcome to SonarSource community! :wave:

The build step needs to happen after your SonarCloudPrepare task. Treat the SonarCloudPrepare task as the “begin” step, so your SonarCloudPrepare@1 task needs to precede your build step.

Some extra tips:

  • Make sure your DotNetCoreCLI@2 task is pointing to the .sln file. For example, I have a .sln file that’s within the src folder relative to the root of the project (base directory):
    - task: DotNetCoreCLI@2
      inputs:
        command: 'build'
        projects: 'src/Blorc.OpenIdConnect.sln'
    
  • Move any Sonar analysis parameters into your SonarCloudPreapre@1's extraProperties key like so:
    - task: SonarCloudPrepare@1
      inputs:
        SonarCloud: 'SonarCloud'
        organization: '<org>'
        scannerMode: 'MSBuild'
        projectKey: '<key>'
        extraProperties: |
          sonar.verbose=true
    

Please show the logs if you get any other issues you would like resolved.

Joe

Hi Joe,

Perfect, yes, that fixed the problem. Thank you!

I figured it was something simple, I missed that detail.

Thank you,
Erik

1 Like

A post was split to a new topic: .NET core project Sonar analysis is empty but SonarLint shows issues

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