Azure, Cloud Computing, DevOps

6 Mins Read

Easy Steps to Integrate SonarQube with Azure DevOps Pipeline

TABLE OF CONTENT

1. Introduction to SonarQube
2. Setup SonarQube on Ubuntu 20.04
3. Create a Virtual machine on Azure Portal
4. Guide to Install SonarQube on 20.04
5. Connect to a new project using Azure DevOps
6. Conclusion
7. About CloudThat
8. FAQs

 

Introduction to SonarQube

SonarQube is an open-source platform used for code analysis and code quality checks. It provides us a piece of detailed information detailed, vulnerability, report bugs, error, code duplication, code smell, and much more.

It is a static code analysis tool that has become extremely popular because its code analysis code properties make code cleaner, more straightforward, and bug-free. It supports more than 25+ programming languages and has server plugins and extension support.

In this blog, we will learn how to install SonarQube and intergrade it with the Azure DevOps pipeline.

Setup SonarQube on Ubuntu 20.04 and Integrate with Azure DevOps

We will install SonarQube on Ubuntu 20.04. For SonarQube integration, we are using an ubuntu 20.04 machine launched on Azure Virtual machine.

Create a Virtual Machine on Azure Portal

  1. Open https://portal.azure.com/ and log in to your Azure account.
  2. After logging in to the portal, go to the search box and search for a virtual machine, then click on a virtual machine
  3. Click on create/add the virtual machine
  4. Create a new or choose an existing resource group with a subscription. Enter your resource-group name
  5. Under Instance details, enter the name-of-VM for the Virtual Machine name, choose ubuntu 20.04 for the Image, and leave other configuration as default
    SonarQube Azure DevOps
  6. Under Administrator account, provide username and password for login to the server
  7. Under Inbound port rules, we must choose HTTP (80) and RDP (3389)
  8. Also, we must enable 9000 ports to access SonarQube
  9. Now keep all settings as default and click on review and create
  10. Now click on review and create and then click on create
  11. Go to resource after resource deployment is completed
  12. Now go to networking inside your VM and add 9000 ports for SonarQube
    SonarQube Azure DevOps

After creating a Virtual Machine, we get a public IP that is assigned to your virtual machine.

Now we are good to go. Just SSH into your Ubuntu machine, and let us set up SonarQube.

Guide to Install SonarQube on 20.04

  1. Install java- open jdk 11

  2. Postgres DB Setup

  3. Now start and enable postgresql

  1. Login as postgres user
  2. Create a user

  1. Switch to sql shell by entering

Execute these three lines:

Then save it using: \q

Then type exit to come out.

  1. Download SonarQube and Install

We are using a community version of SonarQube for this lab.

  1. Create Group and User:

  1. We must add the user with access

  2. Modify sonar.properties file

Add the below line:

Sonarqube Azure DevOps

Now press the escape button and enter :wq! To exit.

  1. Edit the sonar script file and set RUN_AS_USER

Add enable the below line

  1. Execute the below command to get values each time serve start automatically:

  2. Kernel System changes

14. Next, we are going to edit limits.conf. Open that file with the command:

  1. Start SonarQube Now

Then type q to come out.

  1. Check if Sonarqube is up and running. This may take a few minutes.

Make sure that sonarqube is Up status.

To open your SonarQube portal get your public IP and use the below URL format to open it:

Now to go to any browser –>your_sonardqube_publicdns

Sonarqube Azure DevOps

Log in using admin; that is a default username and password. Then it will ask for a password change. You can change it as per your need.

Connect to a new project using Azure DevOps using SonarQube

Now you can connect to a new project using Azure DevOps using SonarQube to get logs and check code quality.

Go to My account>> security>> generate Token, give it a name and click on generate.

IMPORTANT: Make a note of these tokens and paste it into Azure DevOps for creating a connection (check this in step 7 of Create a service connection between Azure DevOps and SonarQube).

Now let us create a service connection between Azure DevOps and SonarQube (creating a service connection in azure).

  1. Go to your Azure DevOps, click on organization settings and go to extension
  2. After that, click on Browse marketplace, search for SonarQube tool, and click on the first result.
  3. Then click on get it free and install it
  4. Now the extension has been installed with your Azure DevOps account
  5. Now go to your project, and on the left-hand corner, click on project setting>> service connections>> click on new service connection. Now search for SonarQube
    Sonarqube Azure DevOps
  6. Now you can see the SonarQube extension just click on it and click on next
  7. After that, give a server URL that is http://your_SonarQube_publicdns_name:9000/ and a token that you must generate from the SonarQube interface for connection. Then provide a connection name, check Grant access permission to all pipelines, and save it.
    Sonarqube Azure DevOps
  8. After saving the SonarQube Token, it will appear in service connections

Now, we must add tasks to your azure pipeline: Preparing analysis configuration, Running code analysis, and publishing quality gate results. Also, we must configure and prepare an analysis on the SonarQube task first. Select the connection you created in the Azure DevOps portal. Select the standalone scanner and then select manually provided configuration and paste the project key we created from SonarQube in step 3.

Then, save the configuration, and you can check your code configuration by running the pipeline.

Sonarqube Azure DevOps

After all these steps and SonarQube configuration, we can see the logs on SonarQube.

Conclusion:

We have successfully installed and configured SonarQube with the Azure pipeline that can check your code quality and do code analysis, improve your quality check, security, unit test, duplications, and remove bugs and vulnerabilities from your code.

Now you can track our code which has been integrated with your infrastructure also SonarQube has great support for more than 20+ programming languages also extended plugins that are used by the organization to build their software applications.

Also, it has seamlessly integrated with SSO, JIRA, LDAP, and CI/CD such as Jenkins and all.

About CloudThat

CloudThat is the official AWS (Amazon Web Services) Advanced Consulting Partner, Microsoft Gold Partner, Google Cloud Partner, and Training Partner helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

CloudThat is a house of All-Encompassing IT Services on the cloud offering Multi-cloud Security & Compliance, Cloud Enablement Services, Cloud-Native Application Development, and System Integration Services. Explore our consulting here.

If you have any queries about SonarQube, DevOps, or AWS CI/CD pipeline, drop them in the comment section and I will get back to you quickly.

FAQs

  1. What is the main requirement of SonarQube?

Developers develop large projects with big code that requires serving the customer. So, it is essential to have excellent code quality and duplication, and SonarQube provides great quality help to improve code quality.

  1. How can I download SonarQube and Sonar Scanner?

Download the sonar-scanner-based platform you used here: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

WRITTEN BY Swaraj Sirsat

SHARE

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!