All the Branch analysis are showing as Passed

SonarQube: * Developer Edition * Version 8.8
The scanner on Jenkins: sonar-scanner-4.6.1.2450-linux
Jenkins Plugin: https://plugins.jenkins.io/sonar/

I would like to scan based on the branches from the Jenkins, passing the branch name as a parameter to the sonar scanner Jenkins pipeline job.

stage('Code Quality Check via SonarQube') {
   steps {
       script {
          
       def scannerHome = tool 'sonar-scanner';
           withSonarQubeEnv("sonarqube-server") {
           sh "${scannerHome}/bin/sonar-scanner \
          -Dsonar.projectKey=XXXXX-be-jenkins \
           -Dsonar.sources=. \
           -Dsonar.host.url=https://sonarqube.XXXXXXXX.com \
          -Dsonar.login=********************** \
          -Dsonar.branch.name='${params.BRANCH}'"
               }
           }
       } 
   }

All the scans return the passed value and not showing the scanning result on sonarQube. while running without sonar.branch.name properties it showing the bugs and scanning report.

Let me know how I can resolve the branch analysis issue.

Hey there.

Do you see issues when you click over to Overall Code?

@Colin_SonarSource

All the branches showing like this. No result on scanning,

Output from Jenkins Build

INFO: rule: S6096, entrypoints: 4
INFO: Running symbolic analysis
INFO: rule: S6096 done
INFO: Sensor JsSecuritySensor [security] (done) | time=830ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=16ms
INFO: CPD Executor 2 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 1 file
INFO: CPD Executor CPD calculation finished (done) | time=10ms
INFO: Load New Code definition
INFO: Load New Code definition (done) | time=202ms
INFO: Analysis report generated in 406ms, dir size=463 KB
INFO: Analysis report compressed in 318ms, zip size=249 KB
INFO: Analysis report uploaded in 1343ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarqube.xxxxxxxx.com/dashboard?id=be-jenkins&branch=CO_V1.0
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarqube.xxxxxxxx.com/api/ce/task?id=AXl-xxxxxxxxxxJtk374Pc
INFO: Analysis total time: 25.724 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 30.000s
INFO: Final Memory: 32M/110M
INFO: ------------------------------------------------------------------------

I don’t know why the Developer edition analysis via branch-wise. Also, sonarqube short-lived branches option is not available on configuration.

The logs make me pretty suspicious – which (and how many) files do you see being indexed by the scanner? Do you expect to see more/others? Adding -X to your scanner command will help you get output like this.

21:23:32.329 INFO: Load project repositories (done) | time=127ms
21:23:32.329 DEBUG: 'Person.js' generated metadata with charset 'UTF-8'
21:23:32.332 DEBUG: 'Person.js' indexed with language 'js'
21:23:32.333 DEBUG: 'README.md' indexed with no language
21:23:32.334 DEBUG: 'sonar-project.properties' indexed with no language
21:23:32.335 INFO: 3 files indexed

Please find the output

14:09:58.201 INFO: Load project repositories (done) | time=216ms
14:09:58.201 DEBUG: 'prettier.config.js' generated metadata with charset 'UTF-8'
14:09:58.202 DEBUG: 'prettier.config.js' indexed with language 'js'
14:09:58.204 DEBUG: 'src/container.ts' indexed with language 'ts'
14:09:58.205 DEBUG: 'src/const/serverRoutes.ts' indexed with language 'ts'
14:09:58.207 DEBUG: 'src/const/types.ts' indexed with language 'ts'
14:09:58.208 DEBUG: 'src/index.co.ts' indexed with language 'ts'
14:09:58.210 DEBUG: 'src/index.ts' indexed with language 'ts'
14:09:58.211 DEBUG: 'src/co/modules/auth/Iauth.ts' indexed with language 'ts'
14:09:58.213 DEBUG: 'src/co/modules/auth/auth.ts' indexed with language 'ts'
14:09:58.215 DEBUG: 'src/co/modules/upload/upload.interface.ts' indexed with language 'ts'
14:09:58.217 DEBUG: 'src/co/modules/upload/upload.ts' indexed with language 'ts'
14:09:58.219 DEBUG: 'src/co/modules/healthCheck/interface/index.ts' indexed with language 'ts'
14:09:58.221 DEBUG: 'src/co/modules/healthCheck/interface/healthCheck.ts' indexed with language 'ts'

Also I find an issue with POST submitting

14:10:07.326 INFO: Load New Code definition (done) | time=200ms
14:10:07.541 INFO: Analysis report generated in 415ms, dir size=463 KB
14:10:07.818 INFO: Analysis report compressed in 277ms, zip size=249 KB
14:10:07.818 INFO: Analysis report generated in /var/lib/jenkins/workspace/SonarQube-Pipeline/.scannerwork/scanner-report
14:10:07.819 DEBUG: Upload report
14:10:08.779 DEBUG: POST 200 https://sonarqube.XXXXXXXXX.com/api/ce/submit?projectKey=XXXXXXXXXXX-jenkins&characteristic=branch%3DCO_V1.0&characteristic=branchType%3DBRANCH | time=959ms

{"errors":[{"msg":"HTTP method POST is required"}]}

Let me know your review on this.