Could not find a default branch for project with key

I’m getting the following error when running official action on GithubActions:
“Could not find a default branch for project with key”

  • ALM: Github
  • CI system used: Github Actions
  • Scanner command used: SonarSource/sonarcloud-github-action
  • Languages of the repository: kotlin
  • Error observed: Could not find a default branch for project with key

Workflow file is here.

Project key and organisation are set correctly:
Screenshot 2024-04-04 at 13.33.29

I’ve added SONAR_TOKEN to Github repo just fine:

Please help.

Hey there.

INFO: Check ALM binding of project '"NorseDreki_dogcat"'
INFO: Detected project binding: NONEXISTENT

First things first, it looks like you need to remove the quotation marks from your project key (and org key).

I also noted that your args look a bit funny,

it looks like

args:
  -Dsonar.projectKey=xyz

when it shoudl look like

args: >
  -Dsonar.projectKey=xyz

Try adding that >

I recently had some struggles with getting the GH action to work properly. Feel free to take a look at our workflow file here: terraform-provider-clumio/.github/workflows/test.yml at main · clumio-code/terraform-provider-clumio · GitHub

I added a step to ‘prepare’ the sonar setting programmatically:

    - name: Extend environment for test reports
      # When updating the Go versions in the excluded matrix, update the condition below.
      if: github.repository_owner == 'clumio' && matrix.os == 'ubuntu-latest' && matrix.go == '1.21'
      run: |
        echo "ENABLE_TEST_REPORTS=true" >> $GITHUB_ENV
        echo "REPOSITORY_NAME=$(cut -d/ -f2 <<< ${GITHUB_REPOSITORY})" >> $GITHUB_ENV
        if [[ ! $GITHUB_BASE_REF ]]; then
          # GITHUB_BASE_REF is only set for PRs, we are on a branch.
          echo "SONAR_BRANCH=${GITHUB_REF_NAME}" >> $GITHUB_ENV
        fi

And instead of the args we have a a properties file that reads the environment variables:

sonar.organization = ${env.SONAR_ORGANIZATION}
sonar.projectKey = ${env.SONAR_PROJECT_KEY}

# Parameter from Branch Analysis to target the actual branch being analyzed:
sonar.branch.name = ${env.SONAR_BRANCH}

Note that we have use a matrix workflow and you only want on call of the scanner per pipeline run as they would step on each other. We pass sonar.branch.name if not on a PR because all reports are sent to the main branch when using workflow_dispatch (manual trigger).