QualityGate wrong result on short-lived branch

We have an issue, scanning our java projects and their specific branches with sonarcloud correctly.
We’ve built a CI/CD pipeline with Jenkins. On Git we use GitFlow methodology, meaning
a longlived “develop” branch and shortlived “feature/x” branches for adding new stuff.
The version is set on build-time, containing the branchname and a buildnumber.

We have problems on the Quality-Gate, which is often or even allways Green on feature branches, but when merging back to develop it is getting Red.

We tried two things:
Quality-Gate set to check “new code”. (New Code set to Previous Version)
Result: New code wont be recognized correctly, because just a new build with no changes
will be green, but can be red when merging back to develop

Quality-Gate set to check “overall”. (New Code set to Previous Version)
Here the quality gate on a feature-branch to check for “overall” is completely ignored. (Is this a Bug?)
It will be allways green. And could be red when merging back to develop where the “overall” check seems to work.

The Quality-Gate should response a correct result in a feature-branch, because
the quality needs to be improved on this branch before merging back to develop.
This leads to very unsatisfied use of sonarcloud for a lot developers on our side.

Do you have any solution how to tackle this problem?
Or is there some Bug regarding “overall” quality checks on shortlived branches?

Hey there.

On a short-lived branch, only Quality Gate Conditions On New Code are being checked. The reasoning being that only New Code should exist in the short-lived branch, and that is what developers should be focusing on when they’re working to merge their pull request. Yes – this means that the Quality Gate of your main branch can be red after the merge a short-lived branch / pull request that was green, if:

  • The Quality Gate of your main branch was already failing before
  • You had a super small changeset that didn’t trigger certain Quality Gate conditions (see SCCOMM-41)
  • Your Quality Gate conditions on Overall Code are stricter than the conditions on New Code

Which Quality Gate conditions are failing post-merge, and what is the overall configuration of your Quality Gate (a screenshot would be helpful here).

Hi Colin

Thanks for your explanation. You are true about the focusing for only on the new code.

For the New Code beeing checked we have the problem that we cant configure that the “new code” is correctly recognized.
For example, when we add new code, on first build run, the code is getting checked correctly (lets consider red for now because test-coverage is to low). But on a second build run
without any changes, it will be green, because there is no new code found. Then green it means we can merge back to develop, and on there it will be red again.
So all the code in the feature branch, that differs from branch develop should be considered new code. But I have no clue how to configure such a scenario?

One other thing is that i find it really bad, that you can configure such a quality gate for overall code, but has completly no effect on short-living branches.