Can't get SonarCloud To Work On AzureDevops With .NET 6

Hello.

We’ve recently signed up for SonarCloud and trying to set it up. We’re hosting everything on AzureDevops and we can’t get it to work at all. Followed the setup guide carefully and did everything as said but we keep getting:

##[error]ERROR: Error during SonarScanner execution

ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

ERROR:

ERROR: Error during SonarScanner execution

ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

ERROR:

##[error]The SonarScanner did not complete successfully

Here’s the full pipeline:

trigger:
- staging

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- checkout: self
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '6.0.x'
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'config'    
    nugetConfigPath: 'Nuget.config'
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'CloudSonar'
    organization: 'smartlocating-dev'
    scannerMode: 'MSBuild'
    projectKey: '<properKey>'
    projectName: '<properName>'
- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '**/XUnitTests.csproj'
    arguments: '--configuration Release'
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '-o $(Build.BinariesDirectory)/publish -c Release'
    zipAfterPublish: false
- task: SonarCloudAnalyze@1
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.BinariesDirectory)'
    ArtifactName: 'core_rest_elastic_bin'
    publishLocation: 'Container'

We made sure that the projectKey and name are exactly like they are in SonarCloud (and in the tutorial) so they are not wrong. If anyone can help please let us know what to do as we are hardstuck on this step. Thanks!

Hi,

Welcome to the community!

I guess this is a private project? I ask because you’ve double-checked the projectKey and organization values, but there’s another possibility listed in that error message:

So can you check the token too?

 
Ann

1 Like

The token is added in the connection on azure devops right? Or is this an extra step that needs to be done somewhere else in the pipeline?

If it’s in the connection then it’s added and verified. Thanks!

Edit: Sorry, i completely forgot to answer the question. It is a private project :slight_smile:

Tried multiple things today and no luck. I even included the file with the key and name and still doesn’t work with the same error. I re-ordered the steps in pipeline few different ways and still no luck. Made sure the key is ok and is set in the connection.

Hey there.

I would also suggest taking a look at your project-level Administration > Pull Requests or organization-level Administration > Organization settings > Azure DevOps connectivity management and make sure a valid token is set.

Hey hey.

Made sure proper token is inserted in both location and it is. PAT token with full access provided in both locations and it still isn’t working.

Same error again

ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

Any other ideas i could try to get it to work?

@vulegend the pipeline looks fine. A couple of things to recheck:

  • the user has Execute analysis permission. I’m guessing from what you’ve said that the project already exists in SonarCloud, so they shouldn’t need the ‘Create project’ permission.
  • re-create the token, and edit the Azure DevOps Service Connection to use the new token.

Also, can you analyse a simple dummy project with a different project key? (e.g. a newly-created empty .NET Core Class Library app)

If that doesn’t work, we’ll probably need to see the detailed logs for the SonarCloudPrepare and SonarCloudAnalyze steps, which means adding sonar.verbose = true to the SonarCloudPrepare step e.g.

        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true

Let me know you don’t want to share the logs publicly and I’ll send you a private message.