Could not find a default branch to fall back on

I’m getting the following error when running official action on GithubActions:
“Could not find a default branch to fall back on”

  • ALM: Github
  • CI system used: Github Actions
  • Scanner command used: Official GH Action
  • Languages of the repository: c#
  • Error observed: Could not find a default branch to fall back on

Hi @adanlobato-scopely,

This could be related to a misconfiguration of the project key or organization. Could you check if the project key you provided matches the project key on SonarCloud?

If the key is correctly configured could you share the log output of the GitHub action?

I’m experiencing the same issue.

The project “Sirups.Essentials.Mvc” which should be visible here:
https://sonarcloud.io/organizations/sirups/projects

From the github action located here:

I get the following error in the analyze fase (https://github.com/sirups/Sirups.Essentials.Mvc/runs/810083444?check_suite_focus=true#step:10:59):
INFO: Total time: 31.652s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 25M/125M
ERROR: Could not find a default branch to fall back on.
INFO: ------------------------------------------------------------------------
ERROR:
The SonarQube Scanner did not complete successfully
06:07:21.573 Post-processing failed. Exit code: 1
##[error]Process completed with exit code 1.

Hi @CoolMcgrrr and welcome to the community !

Can you double check that your main branch is the default one on SonarCloud ? If you go to Administration -> Branches and pull request, there should be a label “MAIN BRANCH” beside the name of your default branch.

Mickaël

Thanks a bundle! :slight_smile:
I have just verified that my “MAIN BRANCH” is “main”. (Which is as expected)
The action failed on the “main” branch.

EDIT: I think what I wrote was a bit unclear. So just to be on the safe side.
The “Thanks a bundle” was for welcoming me to the community.
As far as I can tell the project is correctly setup in SonarCloud. But I am still getting the error.

Thanks ! How did you create the project on SonarCloud ? Manually, or by choosing the repository on the UI (what we call “onboarding”) ?

I created the project by choosing the repository.

I tried running my Github Action before it was created. (My expectation was that it would be created automatically)
Since that didn’t happen I created it by choosing the repository

Yes because the log suggests that the binding (when the project was created by selecting the repo) was not created at the time you ran the analysis.

So did you tried again with the new setup of your project ? Is it still failing ?

I tried deleting the project in SonarCloud and tried running the action again. I still get “Could not find a default branch to fall back on.”
I can’t see anything special about my repository. I have a branch protection rule preventing pushes to the release branch, but that shouldn’t be relevant here since my Main branch is “main” and the current branch I’m running on is “main”.

If I create it manually without “onboarding” I’m able to get it to work.
However this sets it up with a “master” default branch and my “main” branch as a “secondary” branch.
Is this some issue with SonarQube requiring a “master” branch or something like that?

I tried creating it all over again with the “onboarding” feature (which sets up my branches as they should be) and I get the “Could not find a default branch to fall back on.”.

Hi @CoolMcgrrr

I think you may need to provide the -k:{myProjectKey} in your ci.yml file directly when invoking the Scanner for MSBuild, that should work that way.

Mickaël

A post was split to a new topic: Have two repos (GH and GitLab) under one SonarCloud org

A post was split to a new topic: “Could not find a default branch to fall back on” GitLab Error

The wrong sonar.projectKey was the issue on my side.

My project is here GitHub - n13org/jekyll-kw-loremipsum: LoremIpsum is a jekyll plugin. You can get some dummy text for your webpage, without copy & pasting the Lorem Ipsum words yourself..

I have set up sonar as an organization n13.org and my projectKey is jekyll-kw-loremipsum.
And I saw in the URL: https://sonarcloud.io/summary/new_code?id=n13org_jekyll-kw-loremipsum that the org and the projectkey are combined.

my “wrong” projectKey was: sonar.projectKey=jekyll-kw-loremipsum I switched to sonar.projectKey=n13org_jekyll-kw-loremipsum (so i prefixed my project key with the org) and the scan was successfully done.

Thanks for advice, it really helped

Hey, hope you are doing well.

I faced a issue is that Could not find a default branch for project with key "android-bvs", I already created the project with the correct project key.

Java17

Could you please help to check? I created multiple projects for other repositories, and it works when I created it, but it does not work now.

I run it with Java11, it failed with following error.

It works for me after fixed the wrong token, the token was managed by others, so I don’t check it before.
Sorry for bother. :pray:

I, and some other in my team on another repo, are suddenly facing this error message. We didn’t change anything on our side regarding the sonar properties, and we’ve made sure the project keys, organisation, etc are correct. We also updated our sonar tokens in Bitbucket but that hasn’t helped either. Any clues what could be going wrong? The only thing is that we aren’t admins on the sonar project - could that affect if the tokens we generate aren’t a high enough permission level?

The full output of the sonarcloud check looks like this:

14:11:29.944 INFO: EXECUTION FAILURE
14:11:29.944 INFO: ------------------------------------------------------------------------
14:11:29.944 INFO: Total time: 5.136s
14:11:29.983 INFO: Final Memory: 9M/27M
14:11:29.983 INFO: ------------------------------------------------------------------------
14:11:29.983 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
	at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:127)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:57)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:51)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:50)
	... 34 more
Caused by: Could not find a default branch for project with key 'XXXXXX'. Make sure project exists.
14:11:29.984 ERROR: 
14:11:29.984 ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
✖ SonarCloud analysis failed. (exit code = 1)

I had a similar issue check that the sonar token have the permissions and that it is well set and not left blank