I know that there is no "new project" button on SonarQube UI. However, I have two branches of the same project that I want to do analysis on. The thing is that since the project names are the same, SonarQube will upload the analysis results of the two branches into the same project on SonarQube Server. How do I configure SonarQube so that one branch will upload analysis results to one project and the other branch will upload results to another project on SonarQube server?
5 Answers
You might want to look at this part of the Sonar documentation, specifically at the sonar.branch parameter. It seems to be designed for what you want to do, and is working that way for us.
-
2Works for us, too. I tried using `sonar.projectKey`, but that is not carried to submodules. – ChristophT Feb 06 '17 at 10:18
-
Hi. We use the branch parameter but we do not see any kind of integration. The documentation states: " Two branches of the same project are considered to be different projects [...] issues found in a project A in a branch B1 are not linked to issues found for this project A in a branch B2." So. What kind of branch support is provided by Sonar? Thanks – borjab Jul 12 '17 at 08:53
-
10SonarQube documentation now states that the sonar.branch is deprecated from SQ 6.6 – Jeroen Pot Nov 14 '17 at 16:14
-
2Apparently, they have some branch support in the Developer edition. Tough luck... – kap Dec 11 '17 at 15:33
-
Indeed, https://docs.sonarqube.org/display/PLUG/Branch+Plugin is available only for Developer Edition, which is not free (: – heroin Jan 23 '18 at 13:08
-
2@heroin: The doc of the plugin doesn't explicitly say so does it? Anyhow I found there is a GPL plugin https://github.com/s-pw/sonar-branch-community (untested) – s.Daniel Apr 26 '18 at 11:50
-
1@s.Daniel I've found that information here: https://www.sonarsource.com/plans-and-pricing/. Thanks for link, I will look on the repo, looks promising. – heroin Apr 26 '18 at 14:43
-
Tested it by now. Seems to be working. At least I can select branches and see new issues introduced in the branch. Note btw: When one tries to install the commercial branch plugin without a licence a licence plugin is installed along the way which stops sonar from working even if you uninstall the branch plugin. You must also remove the licence plugin. – s.Daniel Apr 27 '18 at 15:13
-
3The sonar-branch-community plugin seems to be no longer available. Is there any alternative? – Pabi Jul 09 '18 at 21:28
-
broken link.... – Lorenzo Lerate Jul 25 '23 at 07:50
As the sonar.branch parameter is deprecated and the Developer Edition costs money, one possible option it to use the already mentioned branch plugin for SonarQube Community Edition (LGPL).
Update: seems like the repo is gone, not sure why. Active fork can be found here.

- 1,857
- 1
- 22
- 36
-
4https://github.com/mc1arke/sonarqube-community-branch-plugin currently supports SonarQube 7.4 and above – mc1arke Mar 14 '19 at 20:48
-
So how do you actually use this plugin after downloading and dropping it in the plugins folder? – Johan Aspeling Aug 05 '19 at 12:21
-
1You need to configure your scanner job to submit branch details as part of the scan (https://docs.sonarqube.org/latest/branches/overview/#header-2) at which point you'll then get the option to select which branch to view in SonarQube UI – mc1arke Aug 06 '19 at 07:49
If you use SonarQube Runner, then you have to change the sonar.projectKey
property to different values. If you use maven based analyses, then add -Dsonar.projectKey="Something"
to your command. Example:
mvn sonar:sonar -Dsonar.projectKey="My project in first branch"
mvn sonar:sonar -Dsonar.projectKey="My project in second branch"
You can change the project name in a similar way with the sonar.projectName
property.

- 1,089
- 7
- 11
-
Tried both sonar.projecKey and sonar.projectName, but couldn't force SonarQube to work on a single project module (the multi-module project has previously been processed by SonarQube as a whole): it always complains that the module is already part of project X... :\ Would have come in handy not to have to wait 10 minutes for each iteration while I tweak maven parameters to get the job to run just right. – Tomislav Nakic-Alfirevic Sep 03 '15 at 11:17
-
7
-
This blog post by the SonarQube team suggests that treatment of branches will be improved in version 6.
Additionally, if you are using pull requests, have a look at its pull request analysis plugins (both GitHub and BitBucket at the moment).

- 2,232
- 3
- 28
- 37
-
Well. We use 6.3.1 and add the sonar.branch parameter but it still seems to create a project by branch. Are we doing something bad or it is just that Sonar didn't implemente a lot of improvements with this parameter. – borjab Jul 12 '17 at 08:39
The sonar.branch parameter is deprecated from sonar version 7.1 so, for alternative for that and having separate branch analysis on sonarQube version 7.1 on-words you can use something like this.
I assume you have maven project. if not just remove -D from it and use it.
mvn sonar:sonar -Dsonar.projectKey=<projectname>
mvn sonar:sonar -Dsonar.projectName=<project-name>
The project key should be unique. Otherwise it will combine the result of other branches who has the same project key.

- 7,956
- 2
- 28
- 42