Skip to content

Sonarqube Configuration

TheSpiritMan edited this page Dec 25, 2022 · 7 revisions

Sonarqube Configuration

  • Sonarqube is an opensource tool used for Code Quality and Code Security.

Sonarqube Requirements

  • We will run sonarqube as a docker container. So docker must be installed in your system.

Sonarqube Container

  • Sonarqube requires a database connection. By default it uses a H2 database engine.

  • In production level, we must use our own database but for now we will use the H2 database engine which is preconfigured in docker image.

  • Even we use the H2 database, we can still create a docker volume and save the resource for future use. For that, we will create 3 volumes.

  • By default, sonarqube runs in port 9000.

  • The command to run the sonarqube container:

    docker run -d --name sonarqube -v sonarqube_data:/opt/sonarqube/data -v sonarqube_extensions:/opt/sonarqube/extensions -v sonarqube_logs:/opt/sonarqube/logs -p 9000:9000 sonarqube:lts
    
  • Remember, if the docker volume with the same name is already present in the system, it will simply used that volume. But if the docker volume is not present then it will create the new volume and mount it to the containers.

  • It takes 1-2 minutes for sonarqube to load up.

  • Once started sonarqube, visit http://<your_ip>:9000. For my case, it is http://192.168.18.8:9000.

  • We must enter the username and password to access the sonarqube dashboard.

  • Enter the admin as username as well as password.

  • Then we will be asked to reset the password. In my case, password will be admin123.

  • We can see the dashboard of the Sonarqube.

  • GoTo Administration, then Security and then Users.

  • Select the tokens from the right column.

  • Give a meaningfull name for the token. I am giving jenkins.

  • Click on Generate buttom. Then token will be created. We must copy and save it in some file.

  • Once click on done, we can no longer retrieve the value of the token.

  • Keep the token stored in some file for a moment. We will use this token to connect Jenkins with the Sonarqube instance.

For now sonarqube's work is done. Now go to Jenkins Configuration.

Jenkins Webhook Configuration

  • Goto Administration, then Configuration and select Webhooks.

  • Now we see create button, click that button. A form will be prompted to fill up.

  • Fill the details, remember to give the url of the jenkins in a private ip not as a localhost.

Go back to Jenkins Configuration in Test Case 3.

Webhook Triggerred

  • Once jenkins job is triggerred, if everything goes well, the webhook must return success as below:

Conclusion

Sonarqube is fully configured which means now we do not need to change anything in the Sonarqube Instance. To continue with the project, visit Jenkins Configuration and follow the documentation.