Project not found, with create permissions

Hi, there!

I’m an administrator for several SonarCloud organizations. One of our customers stated than they can’t perform analysis on a new project over Azure DevOps:


2024-09-19T13:47:48.4505378Z ##[error]13:47:48.440 ERROR Could not find a default branch for project with key '{project-key}'. Make sure project exists.

They have been performing analysis flawlessly, but over projects previously created. We have tried creating this particular project with the UI, and it has worked just right.

I deleted this project and made a test over my machine with the same result:

I have tried the original token and one token of mine. I also tried with another organization. I am, as I said, an administrator and owner of both, with Create permissions.

Is there something I’m missing?

Over Azure, we use:

steps:
  # 1. Preparar el análisis de SonarQube
  - task: SonarCloudPrepare@2
    inputs:
      SonarCloud: ${{ parameters.sonarCloudServiceConnectionName }}
      organization: ${{ parameters.sonarCloudServiceOrganizationName }}
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: "$(Build.Repository.Name)"
      cliProjectName: "$(Build.Repository.Name)"
      cliSources: ${{ parameters.sonarCloudSourcesPath }}
      extraProperties: |
        sonar.branch.name=$(Build.SourceBranchName)

  - script: |
      echo "El SonarCloud es: ${{ parameters.sonarCloudServiceConnectionName }}"
      echo "El organization es: ${{ parameters.sonarCloudServiceOrganizationName }}"
      echo "El cliProjectKey es: $(Build.Repository.Name)"
      echo "El cliProjectName es: $(Build.Repository.Name)"
      echo "El cliSources es: ${{ parameters.sonarCloudSourcesPath }}"
      echo "La sonar.branch.name es: $(Build.SourceBranchName)"

  # 2. Ejecutar el análisis de SonarQube
  - task: SonarCloudAnalyze@2

  # 3. Publicar los resultados del análisis
  - task: SonarCloudPublish@2
    inputs:
      pollingTimeoutSec: '300'

On my machine, I’ve been using:


sonarscanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$TOKEN_SONARCLOUD -Dsonar.organization={org} -Dsonar.projectKey=prueba-prueba

Hi,

How are you creating the project?

 
Ann

We are delegating the project creation in SonarCloud to Sonar Scanner. The scanner is in charge of creating the project in SonarCloud. :slight_smile:

Hi,

So going back to your initial report, are you saying that the initial analysis / project creation is what’s failing? Or is the project created via analysis and your clients subsequently can’t (re)analyze?

And are you able to pinpoint approximately when this failure started happening?

 
Thx,
Ann

Yes! Is the project creation vía Sonar Scanner what’s failing!

If we create the project vía UI and then perform the first analysis, seems to be ok.

First time we saw this was on Thursday, when a customer of us reported it :slight_smile:

Hi,

Are you passing any branch-related parameters in this project creation? I think project creation has to be of the main branch.

 
Thx,
Ann

I don’t use branch parameters on the original command, but I made some test with parameters and none of them has worked:

Original:

sonarscanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$TOKEN_SONARCLOUD -Dsonar.organization={customer org} -Dsonar.projectKey=prueba-prueba

Output:

18:14:16.862 ERROR Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to

Test 1:

sonarscanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$TOKEN_SONARCLOUD -Dsonar.organization={customer org} -Dsonar.projectKey=prueba-prueba -Dsonar.branch.name=master

Output:

18:10:42.176 ERROR main component does not belong to specified organization

Test 2:

sonarscanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$TOKEN_SONARCLOUD -Dsonar.organization={customer org} -Dsonar.projectKey=prueba-prueba -Dsonar.branch.name=main

Output:

18:12:20.584 ERROR main component does not belong to specified organization

Please take note that in the first test I used master and the output is like “main component” and in the second one I used main and the output is the same (Timestamp changes, ovbiously)

1 Like

Hi,

Thanks for verifying that. I’m going to flag this for the team.

 
Ann

Hi @mbastardo.excentia

At as now, SonarCloud does not provision projects upon first analysis. Therefore, currently, you have to create the project before you run the first analysis.

This issue was referred to in this other thread.

We do have a feature request for this capability, however, it is not prioritized at the moment. I will share this with our product manager.

@AlxO

Hi, Alex, thank you for your response.

Could at least the message in sonarscanner be more specific?

“You could not create the project vía first analysis. You may create the project on SonarCloud and then perform the first analysis”

Where do I found this feature request? I think I should give a push in order to get done.

Thanks :slight_smile:

1 Like