Sonar Qube

 SonarQube in Azure DevOps is a code quality and security analysis tool that integrates into your Azure DevOps pipelines to automatically scan your code for issues such as:

  • Code smells (bad practices)

  • Bugs

  • Vulnerabilities

  • Duplications

  • Security hotspots

  • Coverage from unit tests


πŸ” What Is SonarQube?

SonarQube is an open-source platform that:

  • Analyzes code across multiple languages (C#, Java, JavaScript, Python, etc.)

  • Enforces quality gates to fail builds if code doesn't meet standards

  • Helps teams track technical debt and improve maintainability


πŸ”§ How It Works in Azure DevOps

πŸ’‘ Use Case

When you're running a CI/CD pipeline in Azure DevOps (using YAML or classic), you want to automatically scan the code and fail the build if it doesn't meet your team’s code quality standards.

🧱 Key Components

  1. SonarQube Server:

    • Either hosted by you or use SonarCloud (SaaS version).

  2. SonarQube Extension for Azure DevOps:

    • Install from the Azure DevOps Marketplace.

  3. Pipeline Tasks:
    In your pipeline, you typically use:

    • Prepare Analysis Configuration

    • Run Code Analysis

    • Publish Quality Gate Result


✅ Example: YAML Pipeline Integration

yaml

trigger: - main pool: vmImage: 'ubuntu-latest' steps: - task: SonarQubePrepare@5 inputs: SonarQube: 'MySonarQubeServiceConnection' scannerMode: 'CLI' configMode: 'manual' cliProjectKey: 'my-project' cliProjectName: 'My Project' cliSources: '.' - script: | dotnet build displayName: 'Build project' - task: SonarQubeAnalyze@5 - task: SonarQubePublish@5 inputs: pollingTimeoutSec: '300'

🧠 Why Use SonarQube with Azure DevOps?

FeatureBenefit
πŸ” Security ScanningIdentify vulnerabilities and security hotspots early
πŸ“ˆ Code Quality GatePrevent merging poor-quality code
πŸ” Continuous FeedbackCatch issues in pull requests
πŸ‘₯ Team MetricsMonitor technical debt, complexity, and coverage

πŸ†š SonarQube vs. SonarCloud in Azure DevOps

FeatureSonarQubeSonarCloud
HostingSelf-hostedSaaS (cloud)
IntegrationAzure DevOps, Jenkins, etc.Azure DevOps, GitHub, etc.
PricingFree (Community) / PaidFreemium
SetupMore control, more complexityEasier setup

Comments

Popular posts from this blog

πŸ€– Copilot vs Microsoft Copilot vs Copilot Studio: What’s the Difference?

Automating Unique Number Generation in Dynamics 365 Using Plugins

In-Process vs Isolated Process Azure Functions: What’s the Difference?