The Quality Gate
plugin is useful if we want to fail the Jenkins job based on the result of Quality Gate:
- Install the
Sonar Quality Gates Plugin
in Jenkins:
- As of now, Quality Gate is passed for our sample application:
- Go to the
Quality Gates
tab and add a condition where if issues are greater than 10, then it should give an error.
- In the same
PetClinic-Code
build job, as aQuality Gates SonarQube
plugin action fromAdd post-build action
. It asks for the Quality Gates configuration in the Jenkins configuration:
- Go to
Manage Jenkins,
click onConfigure system,
and configure Sonar instance forQuality Gates
:
- We already have
sonar-project.properties
in the application. Note the project key:
- In the Jenkins job, enter the same
Project Key
and clickSave
:
- Click on
Build now
to execute a Jenkins build job.
- The Jenkins job has failed. Go through the console output and the reason will be Quality Gate failure:
- Go to the SonarQube dashboard and verify the reason for
Failure
andQuality Profile...