How can I use Sonar maven plugin to validate local code against Quality Gate?

Viewed 1396

We have our project integrated with SonarQube remote server, with a Quality Gate configured. Everytime we commit in master our gitlab executes that sonar:sonar and if the code doesnt meet the Quality Gate metrics , the build is rejected.

I would like to do the same in local before pushing to Gitlab.

If I execute sonar:sonar in local pointing to the remote SonarQube server it verifies the Quality Gate and persists the metrics in the server.

But, I would like to do the same without persisting the metrics as it's my own branch. So, if I use -Dsonar.analysis.mode=preview it doesnt persist metrics but it doesnt check the metrics ( Quality Gate )

Is there any way to do it ?

2 Answers
Related