New Code results differ between main and feature branches

  • SonarQube Enterprise 8.5.1.38104
  • Feature branches are not comparing new code correctly, which affects quality gates

When we are building our feature branches, we compare against our main branch for new code, and our main branch compares against the previous version. Since upgrading to 8.5, the new code metrics have been inconsistent. Our feature branches are building and passing the quality gate, but once merged to the main branch, the quality gates fail due to missing coverage, drops in reliability, or security issues. I’ve attached screenshots showing the feature branch passing, the main branch after merge failing, and our new code settings.



Thanks

Hi,

Your branch snapshot (from 4:54 p.m.) shows 100% coverage on 1 line. Your develop/main snapshot (from 8:48 p.m. - presumably post-merge) shows 43% coverage on 14 lines. So I think this is not about the merging of that one branch but possibly of several - or at least of one more.

Several years ago we introduced a control to not apply QG conditions on Coverage (overall Coverage?) when there are fewer than 20 new lines. AFAIK, this is still in force. It would explain why a PR could pass with low coverage on just a few lines, but then cumulatively multiple merged PRs could push the Project over the QG threshold.

Your next question is why you would be seeing a failed QG on 14 “New Lines to cover”. Here we come to the differences among (Docs reference):

  • Lines - carriage returns
  • Lines of code - “Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment.”
  • Lines to cover - [We don’t actually have a definition of this, but I believe it’s a subset of Lines of Code which omits, e.g. includes, comments &etc.]

If you check your Measures page, you’ll probably see that while you only have 14 New Lines to cover, you have more than 20 New Lines.

And yes, some of this could certainly be improved. Feel free to watch and vote for the related tickets:

  • SONAR-10231 - refine metrics used by Quality Gate fudge factor
  • SONAR-10485 - Provide a way to configure the Quality Gate fudge factor

 
HTH,
Ann

Nope, this is only merge of a single branch.

Hi,

Your branch screenshot shows 1 New Line to cover, and your Develop screenshot shows 14. I don’t know how else to explain that.

 
Ann

The new code metric is wrong on the branch. This was working in 8.4.

Hi,

I don’t understand this. Wrong how? Are you saying it mis-counts the number of lines to cover? Can you provide analysis logs for the branch?

 
Ann