Setting Reference branch at a project settings level will display "This branch is configured to use itself as reference branch" for all branches

I am running Sonarqube 8.4.1 Developer edition
I set up New Code to use “Reference branch” and selected master which is my main branch as in the photo.
For each branch “Project settings” is selected and “Previous version” for master branch

After running the analisys on a newly created branch, the measure for the given branch displays the following text: “This branch is configured to use itself as reference branch. It will never have New Code.”

Can someone help me with some guidance? Maybe I’m doing something wrong or I’m missing some configuration.
Thanks,
Costina

Hi Costina,

i use this setting in a similar way and it works, see

After this project setting is done, every new branch != main branch should get the project setting
automatically, means master as reference.
The important thing is that main branch has to use previous version, it can not use itself as reference.

I have to use check for existence, create if not, set main branch as reference, set previous version for main branch every time, as it runs as part of a generic Jenkins pipeline that has to work for new and existing projects.

Gilbert

2 Likes

Hi,
Could you please post your scanner logs with debug enabled?

The scanner logs displayed: “SCM provider is disabled. No New Code will be computed.”.
SCM seems to be disabled by default. After enabling SCM everything seems to work as expected.
Thanks for the hint.

AFAIK, sonar.scm.disabled is false by default

sonar_scm_disabled

Maybe it was given as analysis parameter with sonar.scm.disabled=true !?

It seems that the default value is true in SonarQube 8.4.1 image

Hm, it’s Sonarqube Enterprise official version 8.4.1 (build 35646) here.
Maybe there’s a difference between editions ?
Just checked with a fresh community edition on my machine and it has the same default
setting as shown in my screenshot.

The default value should be false. A lot of features in SonarQube rely on the SCM sensor being enabled. Maybe it had been set before the upgrade to 8.4.1?

Yes, but why Reset Default: True in his screenshot !?

Oh I missed that. To be honest, I don’t know how to explain that. I just tested and I also get False as the default.

Strange indeed and the default project scm setting is equal to the global setting.

Hi @Costina,

About the fact that you see that the default value of “Disable the SCM Sensor” is True => First of all, you only see this when you’re in the Settings of a Project. And you see this because in the global settings, this setting has been updated to “True”.
As a consequence, by default, in all of your projects, the SCM sensor will be disabled.

1 Like

I’m having similar symptoms (feature branches all report ‘using self as reference’ when configured to use main branch). I am using “Developer Edition Version 8.4.1 (build 35646)”

We build via Jenkins, which invokes Maven sonar plugin (via sonar:sonar). Our log shows this:
[2020-07-30T23:57:08.312Z] [INFO] Load New Code definition
[2020-07-30T23:57:08.312Z] [INFO] Load New Code definition (done) | time=44ms
[2020-07-30T23:57:08.312Z] [INFO] Computing New Code since fork with ‘develop’
[2020-07-30T23:57:08.312Z] [WARNING] Could not find ref: develop in refs/heads, refs/remotes/upstream or refs/remotes/origin
[2020-07-30T23:57:08.312Z] [WARNING] Branch ‘develop’ not found in git
[2020-07-30T23:57:08.312Z] [WARNING] Failed to detect fork date. No New Code will be computed.

After a bit of hunting around and experimenting, I see the problem.

We use the BitBucket Server plugin (bbs_checkout) to fetch the code in our pipeline. This plugin creates a ‘git-remote’ but with a name that matches the project-name in bitbucket. The sonar plugin is looking for the remote as ‘origin’. Neither plugin allows configuration (sigh!).

As a work-around, I did an explicit ‘git remote add …’ with the ‘origin’ name in my pipeline script (surrounded by a try/catch, cuz of course it fails the second time around). Seems a bit hokey, but fingers crossed, it works.

2 Likes

Thanks for sharing how you fixed it.
Unfortunately there are so many ways to clone and checkout a project that it’s hard for the scanner to always find the branches it needs. If the scanner can’t find the branches, we try to make it visible in the scanner logs and in the project’s dashboard so that it can be fixed. Any feedback on how to improve that is welcome.

Hello Team,

I am currently using the 8.9 version and I’ve been trying to use the New Code Definition with “Reference Branch” but with no luck.

  • I have set the master branch to “Previous Version” I do see that it’s being scanned.
  • I have set the rest to Reference Branch “master”, but when I execute my Jenkins Pipelin which does use a DockerFile with code scaner 4.6.2 i am having an issue during the New Code scan :

INFO: Load New Code definition
INFO: Load New Code definition (done) | time=189ms
INFO: Computing New Code since fork with ‘master’
WARN: Could not find ref ‘master’ in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
WARN: Branch ‘master’ not found in git
WARN: Failed to detect fork date. No New Code will be computed.

I wanted to update the scm. plugins.git but since 8.5 it’s the automatic plugin I can’t upgrade anything. So I am not sure what is the issue here why the master is not found.
should I perform a checkout to master from my Multi Branch Pipeline ?

Thanks

Hi,
I’m guessing that Jenkins is only fetching the branch being built (maybe using the option --single-branch).
You should keep the work directory unchanged so you shouldn’t checkout master. You just need to fetch origin/master. Unless it’s a very large repository and performance is a concern, I’d just do git fetch --all before running the scanner.

Hi Duarte,

Thanks for your quick reply, well, Yes it is a huge repo and it will impact the performance to fetch all at the beginning of the pipeline execution,
So If I can’t checkout master, what do u suggest to have it in my local?

You can fetch a single branch. For example, git fetch origin master.

1 Like

Thanks Duarte,

with Multi branch pipeline, the master was not fetched, using your advice I fetched it and it worked.
Thanks (y)