No code is reported on second analysis, Shows that the main branch has no lines of code

SonarQube Version:
Deployment: docker
Problem
I have set up a GitHub action to run the scanner. On first run the scanner executes successfully and reports analysis on the dashboard. However on subsequent runs, the action runs successfully, quality gate passes but this time no code is reported and it shows the quality gate passed but no other info

checking the code shows no lines of code

The GitHub action step is as follows:

      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
        shell: powershell
        run: |
          .\.sonar\scanner\dotnet-sonarscanner begin /k:"${{env.BACKEND_PROJECT_KEY}}" /n:"${{env.BACKEND_PROJECT_NAME}}" /d:sonar.verbose=true /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.qualitygate.wait=true /d:sonar.scm.exclusions.disabled=true
          dotnet build ${{env.BACKEND_WORKING_DIRECTORY}}
          dotnet-coverage collect dotnet test ${{env.BACKEND_WORKING_DIRECTORY}} -f xml -o "coverage.xml"
          .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

The logs after scanning are:

10:21:12.591 INFO: Analysis report uploaded in 294ms
10:21:12.592 DEBUG: Report metadata written to D:\a\<REDUCTED>\.sonarqube\out\.sonar\report-task.txt
10:21:12.592 INFO: ------------- Check Quality Gate status
10:21:12.593 INFO: Waiting for the analysis report to be processed (max 300s)
10:21:12.698 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=104ms
10:21:17.808 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=104ms
10:21:22.911 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=102ms
10:21:28.014 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=101ms
10:21:33.123 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=104ms
10:21:38.239 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=114ms
10:21:43.353 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=111ms
10:21:48.460 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=104ms
10:21:53.565 DEBUG: GET 200 ***/api/ce/task?id=<REDUCTED>\ | time=104ms
10:21:53.670 DEBUG: GET 200 ***/api/qualitygates/project_status?analysisId=<REDUCTED>\ | time=105ms
10:21:53.681 INFO: QUALITY GATE STATUS: PASSED - View details on ***/dashboard?id=<REDUCTED>\
10:21:53.686 DEBUG: Post-jobs : 
10:21:53.692 INFO: Analysis total time: 51.217 s

Hey there.

Based on the symptoms, it sounds like a clean build isn’t being performed (which is required for analysis). Try executing dotnet build --no-incremental.

I updated the GitHub action to:

      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
        shell: powershell
        run: |
          .\.sonar\scanner\dotnet-sonarscanner begin /k:"${{env.BACKEND_PROJECT_KEY}}" /n:"${{env.BACKEND_PROJECT_NAME}}" /d:sonar.verbose=true /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.qualitygate.wait=true /d:sonar.scm.exclusions.disabled=true
          dotnet build ${{env.BACKEND_WORKING_DIRECTORY}} --no-incremental
          dotnet-coverage collect dotnet test ${{env.BACKEND_WORKING_DIRECTORY}} -f xml -o "coverage.xml"
          .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

and still shows The Main branch of this project is empty

Hi guys

The suggestion to execute “dotnet build --no-incremental” is worth considering as it addresses the symptom of a potential missing clean build required for analysis.

In that case I’d suggest sharing your build/analysis logs, both of a (first) build that results in results, and the second build that results in “this main branch is empty”

Hi
To address the issue, it would be helpful if you could share the build/analysis logs for both scenarios: the first build that generates results and the second build that displays the message "this main branch is empty.