Configure SonarQube on Azure DevOps Pipeline
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
And then we clone this url:
https://github.com/KocSistem/pipeline-examples.git
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.
- Adding “SonarQube Prepare Analysis Configuration” task:
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:
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:
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:
SonarQube:
Hope you find my article helpful. I wish everyone an awesome day!
You can check this article: SonarQube Installation on Windows Server