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.
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
So Mark @markluebbehuesen is right, it’s a bug - also with the latest Sonarqube 10.3 !!
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