Configure SonarQube on Azure DevOps Pipeline

Çiğdem Kadakoğlu
3 min readMar 13, 2022

SonarQube-Maven-SpringBoot-Azure DevOps Pipeline

Hi everyone, I will show you how to create SonarQube pipeline for Maven project on Azure DevOps in this article.

  • Firstly, we will import the Github repository.

Repos → Files → Import repository

cigdemkadakoglu

And then we clone this url:

https://github.com/KocSistem/pipeline-examples.git
cigdemkadakoglu

Pipeline:

Here we will create 3 steps for our maven project. Since it is a Maven project, we don’t need to use “SonarQube — Run Code Analysis” task. We have three dependencies for tasks that we will use.

cigdemkadakoglu
  • Adding “SonarQube Prepare Analysis Configuration” task:
cigdemkadakoglu

We can configure the settings with this task and add additional properties without using sonar-project.properties.

The yaml file should look like this:

- task: SonarQubePrepare@4
displayName: Prepare Analysis Configuration task
inputs:
SonarQube: 'SonarQube'
scannerMode: 'Other'
extraProperties: |
sonar.projectVersion=1.0.0.0
sonar.projectName=springsonarqube
sonar.sources=src/main/java/
sonar.language=java
sonar.sourceEncoding=UTF-8
enabled: true
  • Adding Maven build and release task:
cigdemkadakoglu

We can build our Java project and configure Java or Maven versions with this task.

The yaml file should look like this:

- task: Maven@3
inputs:
mavenPomFile: '$(Build.SourcesDirectory)/sonarqube/sonarqubespring/pom.xml'
goals: 'clean package'
publishJUnitResults: true
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
enabled: true
  • Adding SonarQube Publish Quality Gate Result task:
cigdemkadakoglu

We can see the Quality Gate status in the build summary with this task.

The yaml file should look like this:

- task: SonarQubePublish@4
displayName: Publish Quality Gate Result
inputs:
pollingTimeoutSec: '300'
enabled: false

And pipeline yaml is ready!

You can run pipeline and see the results.

Azure DevOps:

cigdemkadakoglu

SonarQube:

cigdemkadakoglu
cigdemkadakoglu

Hope you find my article helpful. I wish everyone an awesome day!

You can check this article: SonarQube Installation on Windows Server

--

--

Çiğdem Kadakoğlu

Senior Cloud&DevOps Engineer | Instructor | Docker Captain | Azure Solutions Architect | CK{A|AD}-AZ{104|204|305|400|800|801|900}-DP900-AI{900|102}-PL900🐧🐳🌼☕