Sonar CI / CD process setup

I am very new in Sonar … I want to setup the CI/CD process with our code before merge to master branch CI / CD will kicks in and do the code analysis, if build not meeting the quality gate it will fail. if it pass it will merge to the master.

Any step by step guide for new user will be really helpful.

@aushmani Can you please tell me Which CI/CD tool are you using ?

If you are using gitlab then try following :

analysis_mode:
  image: emeraldsquad/sonar-scanner
  stage: analysis
  artifacts:
  script: sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN 
  only:
    - mybranch

Note : You can use your branch in only: field. when you commit the code in specified branch it will start analyse your code and if build not meeting the quality gate it will fail.

For more detail : https://www.vishalvyas.com/2019/05/analize-code-with-sonar-scanner-linux.html