Fail Quality Gate if the code coverage after merge will decrease on master

For each MR, we don’t want it calculate code coverage on the incremental code, instead, we want to compare the code coverage of current long-live branch (in most cases, master), and the code coverage after merging a MR to the master.

For example, say Master branch has a overall 73.41% coverage, and we created a MR from feature-branch-1 to master. We expect sonarqube to calculate the code coverage after feature-branch-1 is merge to master. And if that value is smaller than 73.41%, we expect the quality gate would fail.

It would looks like what codecov provides here: [ISSUE #3009]test(benchmark): support delay message test by maixiaohai · Pull Request #3010 · apache/rocketmq · GitHub

(If in the “value”, we can add a branch name instead of a hardcoded, value, that would be great)

Not sure if this feature has been provided yet, thanks for all potential help!

EDIT: SonarQube version: 8.4.1, and yes according to following this can be done using script, but would be nice to have this feature out of box.

As just another user, it might be useful to mention that I needed the same thing, and found that I couldn’t do this out of the box, although the information was available to script my own solution for this.

We’re using SonarQube 7.9.2. You don’t mention what version you’re using.

Our need is that if the scan results in a coverage below the quality gate threshold, it would fail the build that the scan is run from. It would have been nice if the view in SonarQube would also show this failure, but as we’ve noted, we can’t do that.

What I implemented in our Jenkins pipeline code is a script that simply goes to the SonarQube REST api, getting both the details of the quality gate attached to the project, and the measures for the branch of the project, and compares the resulting measurement with the requirement, and fails the build with an appropriate message if the requirement is violated.

1 Like