“main” branch has not been analyzed yet and you have multiple branches already

  • ALM used (GitHub)
  • CI system used (Github Action)
  • Scanner command used when applicable (./gradlew build sonar --info)
  • Languages of the repository (Kotlin)
  • Steps to reproduce
    • Run github action using default gradle template

Hi All,
I need help to fix the issue in my main branch, it didn’t show the analysis.


Hi,

Have you actually analyzed your main branch yet?

I see that you’ve analyzed develop, and I suspect that’s where most of the work happens; what you’d like to be treated as ‘main’.

To make that work, I believe you’ll need to:

  • dump your existing develop branch. You’ll loose your history, but since this is treated as a Short-lived branch, you’re losing functionality and you want to do this anyway
  • analyze develop and override the branch name in analysis to main/masterso it's taken as themain` branch. It’ll come in as “master”, rather than develop, but then you’ll
  • go to the project’s list of branches (shown in your screenshot) and use the 3-dots menu to ‘Rename Branch’ to develop

 
HTH,
Ann

Hi Ann thanks for the support, I already do what you instructed but still no summary from my main branch. Here is what I am doing:

  • Delete develop branch (also in github)
  • Push New Code to main branch

Here is the CI Code:

name: SonarCloud Checking

on:
  push:
    branches:
      - main
  pull_request:
    types: [ opened, synchronize, reopened ]
jobs:
  build:
    name: Build and analyze
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'adopt'
          java-version: '11'
      - name: Cache SonarCloud packages
        uses: actions/cache@v3
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Cache Gradle packages
        uses: actions/cache@v3
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
          restore-keys: ${{ runner.os }}-gradle
      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: ./gradlew build sonar --info


What am I missing here?

Hi,

Can you share the analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

Here is the analysis log

how to fix the error?

I already define the project properties and project org in the gradle

Hi,

The anlaysis log would be everything (inclusive) from the analysis command through that error. But the error is pretty plain. One or more of the following is missing/bad:

  • sonar.projectKey analysis property
  • sonar.organization analysis property
  • SONAR_TOKEN env var

Your pipeline shows you setting the last one. How about the first two? Where are they set?

 
Ann