Clarification on overall vs new code coverage values & "new code period"

Must-share information (formatted with Markdown):
Version used: sonar-scanner-cli-
Trying to achieve: Reflect the correct overall code coverage values based on the latest analysis run on the main branch(or any long living branches).
Things tried so far: Followed the documentation to set up main branch analysis; Configured the “new code” option to “Previous Version”; Doing a code analysis push to sonar everytime our main branch is built on CI.

I am not sure if we have set up the our configs on SC and also our scanner properties properly. But it appears to me that a new code analysis on our main branch is not updating our overall code coverage data.

My expectation(please let me know if this is wrong) is that when a new code analysis happens on a main branch, that becomes the new baseline until the next one happens.

We are using the sonarqube scanner CLI from our bitrise workflows and are not setting the “sonar.projectVersion” in the parameters currently.

What is the correct way to configure/parameterize the new analysis so we see the latest code coverage data on the main branches?

Thanks for the help.

@ganncamp FYI :slight_smile:

Initially when we configured the main branch and pushed up the analysis for that branch, the “sonar.projectVersion” was not set. I have started to pass that param now. And I deleted all the old analysis, but still see a difference between “overall analysis” and “new code”.

How does the “overall analysis” get updated as we keep pushing new versions to the main branch?

The thing that bothers me is that we have set 25% as the code coverage baseline for overall and new code in our Quality gate. Our overall percentage on the main branch is 19.3 and on new code is 25.8. But still the main branch status shows “Failed”.



This depends entirely on how you have your New Code Period configured, and on your analysis configuration

Specifically, it would depend on this particular analysis parameter value. So if you’re not setting this, you’re pretty much guaranteed not to get the behavior you’re expecting.

Yes, this is quite normal. As I explained in another thread:

Let’s say I have 100 LOC overall. Of those 10 are new.
Now let’s say that all 10 of the new LOC are covered → 100% coverage on new code
Let’s further say that the remaining 90 have no coverage → 10% coverage overall

In fact, I would say it would be quite strange if your New & Overall values did match.

Going back to my previous example & assuming your desired configuration of “when a new code analysis happens on a main branch, that becomes the new baseline until the next one happens.”

Let’s say I commit another 100 lines (to keep the math simple) to the main branch:

  • 100 new lines, 200 overall lines
  • Of the 100 new lines, 50 are covered →
    • 50% coverage on new code (50 of the 100 new)
    • 30% coverage overall (the 50 new + the previous 10, which are now no longer “new”)

That’s not the way we recommend doing it. I would drop the Overall condition and just enforce coverage on New Code.

Well, yes. That’s expected since you’ve set a requirement for 25% coverage on Overall code, an you only have 19.3%.


Thanks Ann. I will try removing the overall code criteria from the quality gate and see how it goes for the next few days. I have also added the projectVersion property on the main branch builds.

1 Like