How to integrate sonarqube with Jenkins

  1. Install sonarqube on an instance ( alternatively, you can go to google cloud console -> marketplace -> search for sonarqune -> select sonarqube by Bitnami. This will prepare an instance with sonarqube along with database also installed. I preferred this, as it is a readymade product).
  2. Launch the sonarqube portal ( with the user id and password).
  3. Go to "Administration -> Security -> Users".
  4. Generate a token and note the token id.
  5. Now create a new instance ( in GCP / AWS /Azure as per your wish) and install Jenkins in the instance.
  6. Launch Jenkins with all recommended plugins.
  7. Click Manage Jenkins -> Manage Plugins
  8. Search for "SonarQube for Jenkins" plugin and install without restart
  9. Click Manage Jenkins -> Configure System
  10. Give as below:
 
   
11. Click Manage Jenkins -> Global Tool Configuration
12. Give as below:


13. Go to SSH of Jenkins instance and type the below commands
14. sudo su -
15.  wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
16. apt install unzip
17. unzip sonar-scanner-cli-3.3.0.1492-linux.zip
18.  mv sonar-scanner-3.3.0.1492-linux /opt/sonar_scanner
19. cd /opt/sonar_scanner/conf
20. vi sonar-scanner.properties
21. change the line "sonar.host.url=*sonarqubeinstanceip*"
22. Now create a freestyle job in Jenkins. In "Add Build Step" select the value as EXECUTE SONARQUBE SCANNER
23. In Analysis properties, give the below details (text area):
             sonar.login=token created in step 4
             sonar.projectKey=GitHub respoistory name
             sonar.java.binaries=project/target



24. Build the job.
25. If the build is success, you can visit sonarqube portal and verify



No comments:

Post a Comment