Could not find a default branch for project with key

Hello,
I am using sonarcloud for many project. The issue I am facing is only for new projects. I have a build jobs that at certain time run a command like this one

./mvnw -B -ff -ntp verify sonar:sonar -Dsonar.pullrequest.branch=I-2717 -Dsonar.pullrequest.key=3 -Dsonar.pullrequest.base=staging -Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300

If I did not run the scan from any particular branch, for example staging or any feature branch, my PR scans always fail with the error that the project does not exists. The actual error is

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project onboarding-ivan-todorov-service-aggregator: Could not find a default branch for project with key ‘io.nexo.platform.onboarding:onboarding-ivan-todorov-service-aggregator’. Make sure project exists. → [Help 1]

Once I run the scan from a real branch, then the PR scans are working as expected. It will be a great success if you guide me how to set this, so new projects can be added in the sonarcloud automatically even with PR scans.
Best Regards

Hey @Pavel_P.Pavlov

So just to make sure I understand, these projects don’t exist in SonarCloud when they’re being analyzed, and then the error is being thrown on first analysis? This part is confusing me:

I’m not sure about the difference between a “real” branch and a PR branch.

Hello,
here is an example:
New project, that is not yet scanned by sonar. If I do a pull request which invokes a scan, the scan fails. Here is an example → ./mvnw -B -ff -ntp verify sonar:sonar -Dsonar.pullrequest.branch=NOVA-2680 -Dsonar.pullrequest.key=51 -Dsonar.pullrequest.base=master.
If I run the command from the staging or other non PR branch (./mvnw -B -ff -ntp verify sonar:sonar) the scan is successful.
May be I don’t provide full set of flags for the PR branch.

Best Regards

Did my previous post put clarity on the question? Thank you.

Hi @Pavel_P.Pavlov

Apologies for getting back to you with a long delay.
I checked your project and saw that there have been successful analyses after you reached out to us. Were you able to resolve the issue you had? If not, I could take another look at your problems.
Let me know!