Specify Reference branches automatically

I am using Sonar Entreprise version 8.9.3. Is there a way to automatically set a reference branch for a sub branch without using the sonar portal? I have a project that with branches that represent different versions of the project. We sometime create feature branches and we would like sonar to compare feature branches with the corresponding version branches. This can be done by using the new code portal, and manually specify a reference branch for each feature branch. That can be a bit tedious.

Is there a way to modify a jenkins script or any scripting file to make defining new code automatic? I’m not really familiar with the files in sonar, so I don’t know which file would specify which branch sonar should compare the current branch to and generate new code.

I think the jenkins job mentioned on this post might be what I am looking for but I am not sure what they mean exactly : After upgrade from 7.7 to 8.8: is there a parameter to define new code? - #4 by RSchaeferHIG

Hey there.

While sonar.newCode.referenceBranch as an analysis parameter is available in the latest version of SonarQube (v9.5) it is not available for v8.9 LTS. As far as I’m aware, there’s no good workaround, as in *v8.9 LTS *the branch must absolutely first be created before you can change the reference branch.

Thanks for your reply Colin! I have couple follow up questions if you would bear with me :).

  1. If I was using v9.5, how would I work around using the sonar portal and define new code parameters via code? is the sonar.newCode.referenceBranch option you mentioned a portal parameter or is it something you modify in the backend?

  2. In the post bellow, a user mentioned that they could manipulate the sonar web api along powershell and jenkins to set new code parameters via code. are you aware of any code example I could look at to do the same thing?