New Code on reference branch fails when compared to previous version

Must-share information (formatted with Markdown):

  • which versions are you using : SonarQube Server - Enterprise Edition - v2025.1 (102418)
  • how is SonarQube deployed: zip, Docker, Helm - don’t know use corporate instance

what are you trying to achieve

We are running sonar-scanner in the pipeline on MR (feature branch) and on main branch commits. The run on main branch has the goal to create a reference for following runs on feature branches.

In New Code settings we set to use Reference branch as baseline. Additionally to that we have Set a specific settings for a branch for main. As soon as we use here previous version the pipeline fails on main with New Code showed on Quality Gate page older than one year, despite the fact that previous commit on main is few days old.

My expectation is

  • that calculation of new code for feature branch compares last commit on feature branch and last commit on main.
  • that calculation of new code for main compares last commit on main with previous commit on main.

So I wonder what is the definition of previous version in branch specific settings?

what have you tried so far to achieve this

Switching from previous version to Number of days works fine

Hi,

Welcome to the community!

When you use ‘previous version’, you’re telling SonarQube to look at when the version string (sonar.projectVersion) changed. So it sounds like yours hasn’t changed in the last year.

It sounds like you’re interested in using a reference branch.

This is an anti-pattern. Why? Let’s say my commit raises a new issue and that breaks the Quality Gate. All I have to do is push again. New commit → reset New Code → green QG with the issue still in place.

 
HTH,
Ann

Hi G Ann,

thanks for the great answer!

Meanwhile I found the sonar.projectVersion advise you gave in another thread, it fixed my misunderstanding regarding the previous version term, when I guessed it would be a previous commit. I think that a hint about sonar.projectVersion parameter in the New Code settings dialog, would prevent the question in the forum.

The New Code on our reference branch main is working now as expected :+1:

With regards
Eugen

1 Like