Sonar-maven-plugin - Could not find a default branch to fall back on

Hello,

We have actually a problem with a Sonar analysis on SonarCloud.io

When (in Gitlab) we try to run a pipeline with a Sonar analysis we get this message:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project fcot-backend: Could not find a default branch to fall back on. -> [Help 1]

It happens on branches analysis but also on master…

It used to work like a charm before, but a few days ago we had to change the nature of the Maven project.
At first it was just a simple Maven project. But now it becomes a multi-module project with the same name…

The problems occurred first on the branch for that new re-factoring. Because of that, we decided to delete the project on SonarCloud.io and launch the analysis again. We hopped that the project will be re-created from scratch and resolve our problem. But it was not the case. Since then we tried to launch some pipeline from master even from a commit before the refactoring, but that doesn’t solve the problem either…

About the project:

  • Java
  • Maven
  • Gitlab
  • Organization --> groupemutuelio
  • project name --> fcot-backend

Thanks for your help!

Hello @gbrissonnette,

This error case was added recently and it should only appear when there is no branch on SonarCloud that is marked as the main branch, could that be the case in your project? You can check this by going navigating to Your Project > Administration > Branches & Pullrequest.

SonarCloud should automatically mark the default branch on Gitlab as the main branch on SonarCloud when you import a project from Gitlab. Can you check if you have a branch on Gitlab that is marked as default?

Thanks for your answer,

Yeah I think everything seems right about that subject.

Sonar:


Gitlab:

Thanks, something else must be going on then!
Could you activate debug mode (you can do this by replacing sonar-scanner with sonar-scanner -X in the .gitlab-ci.yml file).

Do you see a
Could not process project branches - continuing without it
message in the log output when running in debug mode?

Yes, you are right.

Here are the logs:

[DEBUG] 12:45:00.296 GET 404 https://sonarcloud.io/api/project_branches/list?project=groupemutuel.io_fcot-backend | time=16ms

[935](https://gitlab.com/groupemutuel.io/digital-transformation/fcot/fcot-backend/-/jobs/534822227#L935) [DEBUG] 12:45:00.297 Could not process project branches - continuing without it

And I can see the same on SonarCloud.io when I go to Your Project > Administration > Branches & Pullrequest . (https://sonarcloud.io/project/branches?id=fcot-backend)

Sorry, on SonarCloud, I get a 200 for https://sonarcloud.io/project/branches?id=fcot-backend

But in the response I get a HTML with

@TomVanBraband any news about that topic?

Hello @gbrissonnette,

I’m currently looking into what might be causing the 404 in your case, and I suspect it might have something to do with your project key. Can you share your project key displayed in the right banner when you view your project on SonarCloud.

I don’t find the right banner that you are talking about…

Maybe it is that one?

I was talking about the banner on the overview page. But that displays the same key as you shared.

The project key usually consists of the organization key combined with the project name. In your case that would be groupemutuel.io_fcot-backend, I suspect that is also the value you have configured in your pom.xml under

<properties>
  <sonar.projectKey></sonar.projectKey>
</properties>

It seems the key of your project does not follow this convention however, setting the key fcot-backend in your pom.xml or updating the key on SonarCloud to groupemutuel.io_fcot-backend should fix your issue.

1 Like

Thanks a lot!

I works like a charm since I changed sonar.projectKey to fcot-backend

I will merge our fix on master and change our project key back to groupemutuel.io_fcot-backend then to come back to a standard situation.

Thanks for you help!

2 Likes

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