Implementing 60% Code Coverage Quality Gate for Specific Directory

Currently, we are using a Quality Gate with 60% coverage as default in our SonarQube. However, we have not achieved the 60% coverage in some directories. Therefore, while keeping the current settings for the analyzed folders, we would like to ensure that at least 60% coverage is achieved only under a specific one directory. Additionally, we would like to know if it is possible to block new code added under this directory from passing the Quality Gate if it does not meet the 60% coverage requirement. Can you tell me if it’s possible.

Hey there.

SonarQube doesn’t let you get as granular as setting specific Quality Gate metrics for specific directories.

It sounds like you’d benefit from focusing your Quality Gates on New Code (see the docs on Clean as You Code) rather than setting conditions on Overall Code.

A Quality Gate that says Coverage on New Code must be at least 60% ensures that all New Code (in this problem directory or not) is above 60%, while not failing any directory where the Coverage of Overall Code is not yet 60%. Once you’ve brought all your directories up to your target, you might consider adding the condition on overall code back.

The other option would be to extract this directory into its own SonarQube project with its own custom quality gate.