Analyzing on new code before pushing to remote SCM

Hello everyone
We established “a remote git server” and " a SonarQube community edition, Ver. 8.4" separately.
We also have Jenkins, Docker and Ansible.

We want before any pushing to a remote SCM, user committed new code be analyzed by SonarQube.
If the scan result and quality gates passed then new code pushed to the repository; Otherwise, give the appropriate message to the user and push action be canceled.

We almost realized can use the " pre-receive hook " or " update hook" in the remote git repository with following settings to connect to the relevant project in SonarQube:

-Dsonar.projectKey= ProjectKey
-Dsonar.projectName= ProjectName SonarQubeURL
-Dsonar.login= SonarQubeToken
-Dsonar.sources= SourcePath
-Dsonar.qualitygate.wait= true

Is using the above method a correct thing to do?
and the written settings are right and sufficient?!

Do you suggest a better solution?
Thank you very much for any help.
Best regards…


Welcome to the community!

This really sounds like a case for SonarLint or PR decoration (starting in Developer Edition ($)).


1 Like

I believe you asked this question on StackOverflow, and I tried to provide some basic information.

Constructing a fully functional CI process takes more than a few paragraphs to describe in detail. You can have shortcuts, like using SonarLint on the desktop, but you really need a full validation of your proposed changes in a pull request, using a full pull request build and sonarqube scan (and other validations) before the pull request can be allowed to be merged.