Confusion on sonar.branch.name usage

13,509 views
Skip to first unread message

kevin.ken...@gmail.com

unread,
Nov 21, 2017, 9:21:28 AM11/21/17
to SonarQube
Good day to you all! 
I've recently been asked to upgrade our SonarQube 6.5 instance to 6.7 Enterprise specifically to take advantage of the sonar branch scanning. I've got a valid license and the installation went smoothly but now I'm stuck in my attempts to get the Branch plugin to work. 

Our project is a multi-module project built in Ant through a Jenkins Pipeline CI system. We use a Jenkins Shared Library to manage the analysis part of the pipeline, and basically build the command line arguments for a call to sonar-scanner. We use GitFlow for our branching strategy and use BitBucket as our repo. 

I'm specifically confused on how all the following work when dealing with the new branches.

My planned organization for the Branch Plugin is as follows:
  1. The "Main" branch is my "develop" branch
  2. The long-lived branches are any "release" branches (and "master" but the evolution of our workflow has gotten away from a central master branch)
  3. The short-lived branches are any "feature," "hotfix," "bugfix," or malformed-named branches

I'm trying to figure out how to get this working (what steps I need to do and when). Assume that I've got a clean SonarQube server. My questions are:
  1. How do I define the main branch? Do I just leave the "sonar.branch.name" information empty? Do I scan this branch first before anything else?
  2. Do I need to change the sonar.project.key for the branch builds or is defining sonar.branch.name sufficient?
    1. We are following the maven <groupId>:<artifactId> pattern with no additional information
    2. Our sonar.projectName is provided through the sonar-project.properties file since we use that for the module
Are there any tutorials or slide decks available that talk about the workflow for getting the Branch plugin? 

Thank you for your advice. I'll be more than happy to clarify things. I'll be experimenting throughout the day.

Julien Lancelot

unread,
Nov 22, 2017, 3:31:36 AM11/22/17
to kevin.ken...@gmail.com, SonarQube
Hi Kevin,

Please contact SonarSource support to ask question on commercial features.

Thanks.
Regards,

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/167da972-1a71-4858-9df4-b602b9204445%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Julien Lancelot | SonarSource

G. Ann Campbell

unread,
Nov 28, 2017, 2:31:58 PM11/28/17
to SonarQube
Hi Posterity,

Kevin has access to our Support department because it comes as part of Enterprise edition, but it is possible to have access to the Branches feature without also having Support. So I'm going to fill in a little here just in case:


On Tue, 21 Nov 2017 at 15:21 <kevin.ken...@gmail.com> wrote:
I'm specifically confused on how all the following work when dealing with the new branches.

My planned organization for the Branch Plugin is as follows:
  1. The "Main" branch is my "develop" branch
  2. The long-lived branches are any "release" branches (and "master" but the evolution of our workflow has gotten away from a central master branch)
  3. The short-lived branches are any "feature," "hotfix," "bugfix," or malformed-named branches

I'm trying to figure out how to get this working (what steps I need to do and when). Assume that I've got a clean SonarQube server. My questions are:
  1. How do I define the main branch? Do I just leave the "sonar.branch.name" information empty?
Yes. 
  1. Do I scan this branch first before anything else?
Or this. The first analysis of a project will automatically be taken as the default/main branch. 
 
  1. Do I need to change the sonar.project.key for the branch builds
No! In fact... the mind boggles at what would happen. This is certainly not something I've tested.
 
  1. or is defining sonar.branch.name sufficient?
Yes! 
    1. We are following the maven <groupId>:<artifactId> pattern with no additional information
    2. Our sonar.projectName is provided through the sonar-project.properties file since we use that for the module
Perfect!

 
Are there any tutorials or slide decks available that talk about the workflow for getting the Branch plugin? 


We'd certainly like to hear about it if something is missing or unclear.


Ann

bek...@googlemail.com

unread,
Jan 26, 2018, 5:55:44 AM1/26/18
to SonarQube
Hi,

we also want to use the branch plugin and had similar confusion, :-), so I tried your suggestions.
Tasks run fine, when I use long living branches, but we have an issue with short lived branches :-(.

Task for short lived branch does the analysis successful and creates a short lived child branch under master, but the result info shows 0 counter and the link to the results shows this error message:

"

We couldn't find any results matching selected criteria.

"

It seems, that the results are stored under the main result page :-(.


Do you have any idea about the cause and the solution?


BR

Bertram

G. Ann Campbell

unread,
Jan 26, 2018, 6:48:07 AM1/26/18
to bek...@googlemail.com, SonarQube
Hi Bertram,

We'll need more details to be able to help. Lets start with your analysis parameters. Also, anything interesting in the analysis log?

Ann

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/5Ru2OLptrfs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/986b2b22-e726-4c32-b46e-28bf62e8b04e%40googlegroups.com.

bek...@googlemail.com

unread,
Feb 1, 2018, 5:38:52 AM2/1/18
to SonarQube
Hi Ann,

thanks for your response.
Have done some further investigations and tests.
Here my analysis parameters:

VERSION=3.6.3
SONAR_PROJECT="jenkins-rundeck-plugin"
SONAR_PROJECT="jenkins-rundeck-plugin"
if [ "$GERRIT_BRANCH" == "master" ]
then
  SONAR_BRANCH=""
else
  SONAR_BRANCH=$GERRIT_BRANCH
fi
##SONAR_BRANCH=short-scm


sonar.projectKey=$SONAR_PROJECT
sonar.projectName=$SONAR_PROJECT
sonar.branch.name=$SONAR_BRANCH
sonar.branch.target=master
sonar.projectVersion=$VERSION
sonar.sources=src
sonar.java.binaries=target/classes

With these settings I get now the expected results if take care on these conditions:
- First run for project should be with branch master
- For short lived branches there have to be source code changes between master and the branch to get analysis results

In my first tests the short lived branch had the same source files than master branch, this was the cause of the empty result page !!!

Thanks for your support :-)

Bertram
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

G. Ann Campbell

unread,
Feb 1, 2018, 7:56:33 AM2/1/18
to Bertram Karch, SonarQube
Hi Bertram,

Thanks for the follow up. I'm glad it's working for you.


:-)
Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/53cdb7b5-43a5-4c51-acdf-0112a07b2d41%40googlegroups.com.

sujit...@gmail.com

unread,
Feb 9, 2018, 3:41:23 AM2/9/18
to SonarQube
Hi Guys,

I am using sonar cloud for our open source project (MSBUILD), when i use sonar.branch.name property in the build analysis fails throwing the following error:

java.lang.UnsupportedOperationException: a measure can be set only once for a specific Component (key=DC-ILR-1718-ValidationService:BRANCH:refs/heads/dev)

what am i doing wrong? I have introduced the sonar.branch.name property recently, earlier analysis was working fine but it was always showing master branch.

Could you please help?

Regards, Sujit
Message has been deleted
Message has been deleted

Sujit Kumar Singh

unread,
Feb 22, 2018, 3:22:10 AM2/22/18
to SonarQube, Hari Prasad
Hi Hari,

First time you need to run analysis without this property from the main branch (master or develop), Sonar will consider first analysis without the branch name as the master branch.

Once first analysis is done in the next analysis if you run the analysis and supply the sonar.branch.name property with the branch name it will work and create the branch in sonar.

This is how it seems to work for us with sonar cloud.

Best Regards, Sujit


On 22 February 2018 at 05:39:07, Hari Prasad (mlhpr....@gmail.com) wrote:

Hi,

The sonar.branch.name doesn't seem to work on project created with first scan without sonar.branch.name="".

Getting the following error when using sonar.branch.name 

build.gradle sonarqube -Dsonar.branch.name=master

 

Gradle failure report

[19:39:32]FAILURE: Build failed with an exception.

[19:39:32]

[19:39:32]* What went wrong:

[19:39:32]Execution failed for task ':sonarqube'.

[19:39:32]Could not find branches. A regular analysis is required before creating branches.


Also sonar.branch.target always seems to default to master.


What the options if we have to mention a different default branch and use sonar.branch.target reliably. Am I missing something?

Regards,
Hari
--

You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/5Ru2OLptrfs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

timothy....@gmail.com

unread,
Apr 24, 2018, 7:41:00 AM4/24/18
to SonarQube
Did you figure this out? I am running in to the same problem. 

I have run an analysis on my main branch(develop) without supplying sonar.branch.name. This worked fine. Then I ran it from a branch with the sonar.branch.name set and am getting this error. 

First run like this

C:\Jenkins\sitecore\develop>"C:\tools\sonarqube\sonar-scanner-msbuild-4.1.1.1164-net46\bin\SonarScanner.MSBuild.exe" begin /d:sonar.login=******** /k:NEON /n:Website /d:sonar.host.url=http://codeanalysis.remoteiv.dk /d:sonar.cs.nunit.reportsPaths=C:\Jenkins\sitecore\develop\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=C:\Jenkins\sitecore\develop\OpenCoverResult.xml


Following run.

C:\Jenkins\sitecore\feature-NEON-10-Setting-Up-Toll-Gate@2>"C:\tools\sonarqube\sonar-scanner-msbuild-4.1.1.1164-net46\bin\SonarScanner.MSBuild.exe" begin /d:sonar.login=******** /k:NEON /n:Website /d:sonar.branch.name=feature-NEON-10-Setting-Up-Toll-Gate /d:sonar.host.url=http://codeanalysis.remoteiv.dk /d:sonar.cs.nunit.reportsPaths=C:\Jenkins\sitecore\feature-NEON-10-Setting-Up-Toll-Gate@2\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=C:\Jenkins\sitecore\feature-NEON-10-Setting-Up-Toll-Gate@2\OpenCoverResult.xml


The error shows:

{"task":{"id":"AWL3Sf5q5_IkahY6f6q6","type":"REPORT","componentId":"AWL3Mrk25_IkahY6f6qw","componentKey":"NEON","componentName":"Website","componentQualifier":"TRK","status":"FAILED","submittedAt":"2018-04-24T12:54:04+0200","submitterLogin":"jenkins","startedAt":"2018-04-24T12:54:05+0200","executedAt":"2018-04-24T12:54:15+0200","executionTimeMs":10155,"logs":false,"errorMessage":"a measure can be set only once for a specific Component (key=NEON:BRANCH:feature-NEON-10-Setting-Up-Toll-Gate), Metric (key=test_execution_time). Use update method (Visit failed for Component {key=NEON:BRANCH:feature-NEON-10-Setting-Up-Toll-Gate,type=PROJECT} )","hasScannerContext":true,"organization":"default-organization","branch":"feature-NEON-10-Setting-Up-Toll-Gate","branchType":"SHORT"}}

I can see that is appends the branch name to the key. But I guess it should do that :-(

/Tim

G. Ann Campbell

unread,
Apr 24, 2018, 8:17:23 AM4/24/18
to SonarQube
Hi Tim,

Please don't cross-post here and on Stackoverflow.


Ann

timothy....@gmail.com

unread,
Apr 24, 2018, 9:28:18 AM4/24/18
to SonarQube
Oh, sorry, won't do that from now on. 

naveen...@gmail.com

unread,
May 11, 2018, 9:32:39 AM5/11/18
to SonarQube
Hi Ann

When I am running the branch analysis with the sonar-administrator group, my analysis is getting passed else the error is "Could not find branches, regular analysis is required before creating branches".
I cannot find any access related point in branch analysis document neither in permissions page.  Does branch analysis need special privilege like administrator ? 

Regards
Naveen

G. Ann Campbell

unread,
May 14, 2018, 7:42:24 AM5/14/18
to Naveen Arora, SonarQube
Hi Naveen,

The account you're analyzing the branch with needs permission to run an analysis on the project. Nothing beyond that is required (assuming the project already exists).


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/5Ru2OLptrfs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/3ca6469c-eeee-4795-b3e6-4bdd5e1195ff%40googlegroups.com.

kevin.ken...@gmail.com

unread,
May 19, 2018, 6:53:00 PM5/19/18
to G. Ann Campbell, Naveen Arora, SonarQube

Naveen,

I found that I had to scan my long term branch (the “master”) without branch scanning enabled. I subsequently turned it on and it has been running fine since then.

I put a flag in my Jenkins pipeline to read an environment variable to turn the branch scanning on/off.

-Kevin

--

To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

 

--

You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/5Ru2OLptrfs/unsubscribe.

To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/CAEi9rUL-zJ38U4VHG1oFeh%3D08rfjKM8g%2BAKap5mL7rNvw1CrFQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages