Reference branch set with 'sonar.newCode.referenceBranch' points to the current branch

Hi, we configured many of our sonarqube projects to have “dev” as the default branch, everything worked fine until about 3 weeks ago, when suddenly, without any changes in the sonarqube or jenkins configurations, we started seeing dozens of Jenkins jobs fail with error:

java.lang.IllegalStateException: Reference branch set with ‘sonar.newCode.referenceBranch’ points to the current branch ‘dev’

we was trying to deploy&analyze the dev branch.

These are the sonar properties in the example jenkins project:

sonar.projectKey=$JOB_BASE_NAME <- dev
sonar.projectName=$JOB_NAME
sonar.branch.name=$WASTE_BRANCH <- dev
sonar.sources=.
sonar.token=$sonar_token

How can we fix this error?

SQ v10.3.0 deployed by docker image 10.3.0-developer

Hey there.

Is it possible that sonar.newCode.referenceBranch got set by somebody in your global SonarQube server configuration on Jenkins (where you specify the SonarQube URL)?

Hi Colin,
unfortunately this is not the case, I checked and there are no custom parameters in the configuration.
Can I check something else?
Thanks a lot for the help.

Thanks. Can you show me how the project-level Administration > New Code of your project is defined? A screenshot would be great.

Hi @Colin, here it is:

all projects default to system settings

That’s the global level – how about one of the individual affected projects?

project-level Administration > New Code

Hi @Colin, this is the project level conf:

and this is the error of tonight’s build:

Thanks for the help

Thanks. I’m flagging this for experts since I’ve run out of ideas.

Thanks @Colin, please let me know if there are any updates

Hello, @pdxeng.

Can you give us which version of the SonarQube Jenkins extension you’re using?

Also, could you, please, send me the full logs of a failing analysis? Ideally, and if you can do it, could you add a -X parameter to the build, so we can have full debug logs? The screenshot below shows where you can add this parameter.

Thanks.

Hi @Andrey_Luiz,
we’re using SQ Scanner v4.8.1.3023 in Jenkins 2.440.1-lts-jdk11.

This is an extraction from a failed execution, please let me know if we can help you in other ways.
Thanks a lot

pe_lib-output.txt (65.2 KB)

Hey @pdxeng.

Thanks for giving us the log.

I have some other questions for you:

  • What do you get if you query the API GET api/new_code_periods/list?project=<project-key>? Can you see something about the branch dev in there? Feel free to send the result here.
  • Have you tried analysing a different branch than dev? Does it work?

Thanks.

Hi @Andrey_Luiz ,
This is the query output:

{"newCodePeriods":[{"projectKey":"pe_lib","branchKey":"core-v1.12-rc","type":"PREVIOUS_VERSION","inherited":true,"updatedAt":1706528607789},{"projectKey":"pe_lib","branchKey":"core-v1.13.1-rc","type":"PREVIOUS_VERSION","inherited":true,"updatedAt":1706528607789},{"projectKey":"pe_lib","branchKey":"dev","type":"PREVIOUS_VERSION","inherited":true,"updatedAt":1706528607789}]}

I was able to run a build without any errors, building from a different branch than dev; unfortunately when building dev the error continues to exist, as you can see in the attached file.

Thanks a lot

sonarqube_issue.txt (4.8 KB)

Hello @pdxeng.

I have a request for you:

  • Can you try to scan the branch dev with the same command as in the logs locally on your machine? Does it work?

I’m sorry for the delay. I’m trying to investigate this to eliminate all possibilities.

Cheers.