Must-share information (formatted with Markdown):
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
Sonarqube Developer Edition Version 8.4.1 (build 35646)
what are you trying to achieve
Apply Quality Gate strictly to code committed on the branch
what have you tried so far to achieve this
Various configurations within Sonarqube
In more depth. Our project has a quality gate that specifies coverage of 80%. Let’s hypothetically say that on Monday, we cut a new version. On Tuesday, we commit 100 lines of code to mainline, with 90 of them covered - at this point, the gateway on the mainline build is happy (90/100 > 80%). On Weds, Alice, a developer creates a feature branch off of mainline, and commits 20 lines of code to the branch, 18 of which are covered - the branch build is also happy (18/20 > 80%).
On Thursday, Bruce, another developer, adds 50 lines of code to mainline, 30 are covered. The mainline build is still happy - ((90+30)/(100+50) = 120/150 >= 80%).
On Fri, Alice decides to merge mainline into her branch. She expects that the branch will still be happy as from her perspective, her branch just has “20 lines of new code, 18 of which are covered”. What appears to be happening though is that Sonarqube is aggregating both Alice and Bruce’s code as “New Code”, and yielding a ((30+18)/(50+20) = 48/70 < 80%) failed gateway result. Alice does not want to be adding coverage for Bruce’s code on her branch. Bruce feels as if he’s done as his code made it to mainline OK. The ‘New Code’ coverage on the branch feels wrong.
Originally, we had ‘New Code’ period on the branch configured as ‘Previous Version’, but after reading more in depth, the above calculation makes sense with that setting.
When we changed the New Code period on the branch to ‘Reference Branch’ (mainline), we inferred that the calculation ought to now be based on the code difference between mainline and branch (i.e. 18/20), but we are not getting that result.
No matter what we do, the branch calculation is polluted by subsequent work from mainline (once merged in). Alice just wants to merge her work and feels her coverage is adequate.