Deprecated analysis parameters

I am using the enterprise edition of Sonarqube version 9.1. I have used the sonar.branch.target parameter for branch analysis and now I am getting the warning below.

Parameter ‘sonar.branch.target’ passed to the scanner is no longer supported. See the Branch Analysis documentation for more information on current branch setup.

This parameter has been removed and I am not sure what I should do for this parameter in the code base.

Hi,

Welcome to the community!

By 9.1, the branch handling model has changed. You’ll analyze without than parameter. Then you can set your target branch as the New Code Period target of your under-analysis branch.

 
HTH,
Ann

Hi,
thank you.

Could you please explain a bit further as I did not understand the solution entirely?

Thanks.

Hi,

Which part didn’t you understand?

You need to drop the sonar.branch.target parameter. Analyze. Then use the UI to set your “branch target” as the New Code Period baseline.

 
Ann

Hi,

I got it thank you so much. The master branch was used as the target branch for the project. If the master branch was scanned the sonar.branch.target was not passed as a parameter. In that case, how do we replicate this behavior?

Hi,

I’m not sure what to say here that’s different than my last response. Analyze your branch. Use the UI to set the main branch as the New Code Period target.

 
Ann

Hi,
I followed the rest of the instructions. I am concerned because when I set the master branch as the reference branch, there is a warning.

Branch master cannot use itself as a reference. Define a specific setting instead of using the project-level setting.

Usually the target branch was not set for master. Which option would it make sense to pick to replicate the same behavior as not setting the target branch?
Available options: previous versions, number of days, specific analysis, and reference branch.
Would the option previous version be the option that makes sense for my requirement?

Hi,

You can set the New Code Period on a branch-by-branch basis. For the main branch, you’ll want to pick a different setting. Typically this is previous_version or something like that.

 
HTH,
Ann

Hi,

Thank you so much for your help and for answering all of my questions.

HI,

After following these instructions I am facing this issue.

This branch could not be compared to its reference branch. See the SCM or analysis report for more details.

Jenkins logs

[INFO] Computing New Code since fork with 'master'
[WARNING] Could not find ref 'master' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
[WARNING] Branch 'master' not found in git
[WARNING] Failed to detect fork date. No New Code will be computed.

Is there a workaround for this?

Hi,

Could you open a new thread for this? And provide your full analysis log in it?

 
Ann

Jenkins does not a full checkout normally, so information about other branches may be missing.
We use this ref spec in the job configuration: +refs/heads/:refs/remotes/@{remote}/

Hi,

as Ann already wrote, after sonar.branch.target has vanished with Sonarqube 8.x, the new code
period has to be set per branch, when previous version is the default version for every branch.

indicates you’ve hit the problem discussed here

We use a generic Jenkins pipeline for maven builds wrapped in a Jenkins shared library.
As we use Jenkins multibranch pipelines, the problem that @reitzmichnicht mentioned is no problem,
as Jenkins creates a job for every branch that fits the multibranch configuration.

You may set the new code definition via web api, see if it works for you

Finally you may vote to bring back sonar.branch.target :wink:

Gilbert

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.