Start Free
SonarQube Community Build | DevOps platform integration | Azure DevOps integration | Adding analysis to Azure pipeline | Gradle or Maven project

Adding analysis to your Azure build pipeline for a Gradle or Maven project

On this page

Before starting, read Azure Pipelines integration overview

Once you have created your project in SonarQube Server and set up feature integration for your project, you can add the SonarQube Server analysis to your Azure build pipeline. 

To create your Azure build pipeline, you can use either YAML or the Azure Classic interface. 

About the analysis parameter setup

Analysis parameters can be set at different levels: see Configuring the project analysis parameters in Creating and configuring your project. You must define the project key in the Prepare Analysis Configuration task of your pipeline. You may define additional parameters in this task the same way. In that case, these parameters have precedence over parameters defined at the project or global level.

Using YAML

  1. Add the SonarQube analysis run to your build task. 
  2. Add the following SonarQube’s tasks:
    • Before your build task, add a Prepare Analysis Configuration task.
    • After your build task, add a Run Code Analysis task.
    • After the Rune Code Analysis task, add a Publish Quality Gate Result task.

See the YAML file example below. See also our YAML pipeline templates. For information about the SonarQube task inputs, see SonarQube tasks for Azure Pipelines.

YAML file example
trigger:
- master # or the name of your main branch
- feature/*

steps:
 # Checkout the repository
 - checkout: self

 # Disable shallow fetch
  fetchDepth: 0

# Prepare Analysis Configuration task
- task: SonarQubePrepare@7
  inputs:
    SonarQube: '<YourSonarqubeEndpoint>'
    scannerMode: 'other'
    extraProperties: 'sonar.projectKey=<YourProjectKey>'

# If you use Gradle: add the Execute Gradle build as shown below
- task: Gradle@3
   inputs:
      sonarQubeRunAnalysis: true

# If you use Maven: add the Execute Maven goal as shown below
 - task: Maven@4
      inputs:
      sonarQubeRunAnalysis: true

# Publish Quality Gate Result task
- task: SonarQubePublish@7
  inputs:
    pollingTimeoutSec: '300'

Using the Classic interface

1. In Azure DevOps' Classic interface editor, create or update your build pipeline.

2. Add a Prepare Analysis Configuration task before your build task:

    • In SonarQube Service Endpoint, select the SonarQube Community Build service connection you created in Adding the SonarQube service connection to your AzDO project in Setting up integration for your project.
    • Under Choose a way to run the analysis, select Integrate with Maven or Gradle.
    • Expand the Advanced section and replace the Additional Properties with the following snippet:
# Additional properties that will be passed to the scanner,
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
sonar.projectKey=YourProjectKey

3. Add a new Maven or Gradle task:

    • Under Code Analysis, check Run SonarQube or SonarCloud Analysis.

4. Add a new Publish quality gate result task on your build pipeline summary.

5. Ensure that the pipeline runs automatically for all the branches you want: Under the Triggers tab of your pipeline, select Enable continuous integration and select all the branches for which you want SonarQube Community Build analysis to run automatically.

6. Save your pipeline.


Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License