Sonarqube 8.9 branch analysis enterprise edition

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Sonarqube: 8.9.7 enterprise edition.
    SonarScanner: 3.3.0.1492
  • how is SonarQube deployed: zip, Docker, Helm
    Zip

I am trying to understand how should i include sonar branch analysis. I am using Jenkins and use like below in Analysis properties.
Master:

sonar.projectKey=com:shared:$GIT_BRANCH_CLEAN
sonar.projectName=Shared
sonar.projectVersion=
sonar.modules=
sonar.sources=.
sonar.java.binaries=.
sonar.exclusions=**/target/**
sonar.coverage.exclusions=**/test/**
sonar.language=java

Non Master

sonar.projectKey=com:shared:$GIT_BRANCH_CLEAN
sonar.projectName=Shared 
sonar.branch.name=$GIT_BRANCH
sonar.newCode.referenceBranch=origin/master 
sonar.projectVersion=
sonar.modules=
sonar.sources=.
sonar.java.binaries=.
sonar.exclusions=**/target/**
sonar.coverage.exclusions=**/test/**
sonar.language=java

issue i am trying to understand if i have one repoistory and in that i have master branch and couple of other branches, once it runs analsyis in jenkins, it is creating different projects for each branch and is not relating master and all the branches of same repositories under same dropdown and in one project.
How can i relate branches of same repositories with master branch of same repository. Ideally it should show me the master branch and in dropdown all the branches which are in that repository and pull requests.

Can you please guide me what configurations should i pass in jenkins master job and jenkins non-master jobs so that all branches in same repository shows analysis under one project with master as main branch and others as dropdown list in same project and it should not create new projets with each branch analysis

###########Logs Non Master branch in jenkins

INFO: Load project branches
INFO: Load project branches (done) | time=5ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=7ms
INFO: Load branch configuration
INFO: Found manual configuration of branch/PR analysis. Skipping automatic configuration.
INFO: Load branch configuration (done) | time=2ms
INFO: Auto-configuring with CI 'Jenkins'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=62ms
INFO: Auto-configuring with CI 'Jenkins'
INFO: Load active rules
INFO: Load active rules (done) | time=1409ms
INFO: Branch name: origin/test-sonar
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/target/**
INFO:   Excluded sources for coverage: **/test/**
INFO: 19 files indexed

Thanks

Hi @harp ,

You need to use the same projectKey/projectName for all branches from the repository.
You must set the sonar.branch.name parameter for each branches.
This documentation may help you.

Something like that should work :
sonar.projectKey=com:shared
sonar.projectName=Shared
sonar.branch.name=$GIT_BRANCH_CLEAN

You have also some parameters for PR see Pull Request analysis

Finally you should think about upgrading to the LTA version 9.9.

Hi @Bachri_Abdel ,

That worked. Thanks a lot for your help.

Regarding PR analysis, it seems if we put sonar.branch.name along with PR analysis parameters. it gives error saying they cannot coexist. We have 2 jenkins project for each repository. One for master and one for Pull Request. Can you please advise how we can do branch analysis and PR analysis in same jenkins project or what is the recommended way to do them so that we can cover both branch analsyis and PR analsysis for same repository via jenkins.