We currently use Sonarqube 10.1 developer edition with Jenkins.
Thank you for introducing the Sonarscanner property “sonar.newCode.referenceBranch”. I have also requested and voted for this property, as you can see in this topic below.
We are using this sonarscanner property in every project via jenkinsfile to set the new code period for each branch. Works as expected, see the following picture
In the GUI, the New Code period is set as follows. Defaults settings, not touched or changed
So, my problem is.
Of course I would also like to use the API to get important information, but unfortunately this is not possible. The query (api/new_code_periods/list? project=abc) via API does not match the New CODE PERIOD set by sonarscanner property. The Information of the query is taken from the GUI. See the following screenshot.
@anon67236913 : Do I understand your answer correctly? You set the new code period by property and then its automatically set in the GUI? A kind of synchronization?
It’s all done via web api calls wrapped in a Jenkins shared library, the Web UI is not involved.
This shared library is part of a generic Maven multibranch pipeline which itself is a shared library
configured via a pipeline.yaml file - this pipeline is used for nearly all Maven projects.
These are the steps for project creation / configuration
Check for project existence /api/projects/search
if no, create it /api/projects/create
Optionally rename the main branch if set in pipeline.yaml
if a branch with that name already exists, it has to be deleted before rename if not set as main
branch already /api/project_branches/delete
rename main branch to the given branch and set as reference branch for all branches /api/project_branches/rename
Set main branch as new code reference for all branches api/new_code_periods/set
Set new code period for main branch to previous version api/new_code_periods/set
Optionally set a special reference branch other than main branch for the $BRANCH_NAME
if set in pipeline.yaml /api/new_code_periods/set
This means it works correctly when using the web api api/new_code_periods/set but it doesn’t
work with the property sonar.newCode.referenceBranch
Subsequent scans of the develop Branch doesn’t change anything, it’s as if the property
is ignored.
So Mark @markluebbehuesen is right, it’s a bug - also with the latest Sonarqube 10.3 !!
yes, it means ‘second step = analysis of the develop branch’ , but i’ve tried also with subsequent analysises, didn’t change anything.
It’s as if the property is ignored completely.
i’ve never used it so far, but if i remember correctly the property sonar.newCode.referenceBranch was introduced in Sonarqube 9.4
So to be sure, i did another test with our production instance = Sonarqube 9.9.0
and also here it behaves like in Sonarqube 10.3 - the property don’t work.
Sorry i was wrong, it behaves exactly as with Sonarqube 10.3
Mixed up pom.xml, then a Git event caused the start of the Jenkins pipeline for the
“xxx.xxx.sonar.custom.java:java-custom-rules” project and this Jenkins pipeline
uses the Sonarqube web api for the new code settings as described in a former posting.
Therefore i assumed at first it would work in Sonarqube 9.9.0
Okay… I have an answer. You’re not going to like it. I don’t like it either:
This is working as designed. Even when used at branch creation, the value of sonar.newCode.referenceBranchis not persisted.
So if you want to use a New Code definition for your branch that’s non-standard for your project, you’ll need to either use sonar.newCode.referenceBranch at Every. Single. Analysis.
that makes me a little thoughtful from a developer’s point of view.
We use the property for every analysis/branch. Without this parameter we have to adapt always the UI especially for short-lived branches.
I really don’t understand what the property “sonar.newCode.referenceBranches” was introduced for if it doesn’t work in sync with the UI or Web API.
In my opinion, if you introduce such a parameter, it should also be fully integrated into the system (UI, Web API).
Sorry, but now it’s only half a job.
@ganncamp : Can you please invite a developer of this parameter to this topic? thx