Sonarqube 8.4.1 branch analysis, definition of new ?!


this is related to


Happy to see Sonarqube 8.4.1 with the changes of

Unfortunately after the first tests, i have to say it’s only half the job done and still not really usable for legacy projects without PR workflows.
Our generic Jenkins pipelines currently running with Sonarqube 7.9.1 simply use the
Jenkins $BRANCH_NAME as with the default = master
and only new conditions in quality gate for legacy projects.
If there is only one new issue on the branch the build fails with quality gate status red.

To achieve the same behaviour with Sonarqube 8.4.1 i need to have a project setting that sets
the main branch as reference for ALL branches.

If using


it works great for all branches, but

this means no more issues on main branch because

As the web api api/new_code_periods/set can only be used after the branch exists, i see no solution.
In fact you need an useless initial analysis creating the branch to be able to set the main
branch as reference. After that a second analysis of the branch shows the issues as expected.

Suggestion => if the project setting would work without affecting the main branch also it would be OK to go with the project setting.
Did i miss anything, is there a solution | workaround ?

If there would only be one analysis at a time, i could change the new code project setting via web api,
$BRANCH_NAME == ‘master’ ? set previous_version : set reference branch master
But there are parallel builds and analysis of different branches of the same project.


Think i’ve found a working hack.

  1. api/projects/search?projects to check if project already exists

  2. api/projects/create if it doesn’t exist

  3. api/new_code_periods/set?project=$projectkey&type=REFERENCE_BRANCH&value=master

  4. api/new_code_periods/set?project=$projectkey&branch=master&type=PREVIOUS_VERSION

  5. run Sonarqube analysis

Thought 3. would not be possible if project is newly created in 2. ,but it is.
Should also be almost safe for parallel builds and scans of the same project !?

After all this is no clean solution, hope it gets polished with the next versions !!

Out of curiousity
What were the reasons to break with the use of the property ??