Setting Up SonarQube on Azure Virtual Machine

SonarQube is a popular tool for continuous inspection of code quality, providing detailed reports on bugs, vulnerabilities, and code smells. Setting up SonarQube on Azure can help streamline your development workflow and ensure high code quality. Here’s a brief guide to get you started.

Step 1: Create an Azure Virtual Machine

  • Log in to the Azure Portal: Navigate to the Azure portal and sign in with your credentials.
  • Create a Resource Group: Go to Resource Groups and create a new resource group.
  • Create a Virtual Machine:
    • Navigate to Virtual Machines and click on “Add”.
    • Choose the appropriate configuration for your VM (e.g., Standard B2s size).
    • Select an operating system (Ubuntu is recommended for simplicity).
    • Configure the network settings and review the summary.
    • Click “Create” to deploy the VM.

Step 2: Install SonarQube on the VM

  • Connect to the VM:
    • Use SSH to connect to your VM: ssh <your-username>@<your-vm-ip-address>.
  • Install Prerequisites:
    • Update the package list: sudo apt-get update.
    • Install Java (SonarQube requires Java 11): sudo apt-get install openjdk-11-jdk.
  • Download and Install SonarQube:
    • Download SonarQube: wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip.
    • Unzip the package: unzip sonarqube-9.9.0.65466.zip.
    • Move SonarQube to /opt: sudo mv sonarqube-9.9.0.65466 /opt/sonarqube.
  • Start SonarQube:
    • Navigate to the SonarQube directory: cd /opt/sonarqube/bin/linux-x86-64.
    • Start SonarQube: ./sonar.sh start.

Step 3: Configure SonarQube

  • Access SonarQube:
    • Open a web browser and navigate to http://<your-vm-ip-address>:9000.
    • Log in with the default credentials (admin/admin) and change the password.
  • Set Up Projects:
    • Create a new project and generate a project key.
    • Configure the project settings as needed.

Step 4: Integrate with Azure DevOps

  • Install SonarQube Extension:
    • Go to the Azure DevOps marketplace and install the SonarQube extension.
  • Create a Service Connection:
    • In Azure DevOps, navigate to Project Settings > Service connections.
    • Add a new SonarQube service connection with your SonarQube server URL and token.
  • Configure Azure Pipelines:
    • Create or edit your pipeline YAML file to include SonarQube tasks:
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'SonarQube'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: '<your-project-key>'
    cliProjectName: '<your-project-name>'
    cliSources: '.'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'

- task: SonarQubeAnalyze@4

- task: SonarQubePublish@4
  inputs:
    pollingTimeoutSec: '300'
By following these steps, you can set up SonarQube on Azure and integrate it with Azure DevOps to continuously monitor and improve the quality of your code. This setup ensures that your development process is streamlined and that code vulnerabilities are identified and addressed promptly.

Checkout:

Comments

Popular posts from this blog

How to update build number in Azure DevOps pipeline?

How to get latest build ID from Azure DevOps pipeline?

How to install AWS System Manager (SSM) Agent on windows using PowerShell?