Skip to content

Instantly share code, notes, and snippets.

@elonmusk408
Forked from rmpestano/qualityGates.groovy
Created February 25, 2021 10:44
Show Gist options
  • Select an option

  • Save elonmusk408/c73d2bc2e67bb9e6d756e3343b71e675 to your computer and use it in GitHub Desktop.

Select an option

Save elonmusk408/c73d2bc2e67bb9e6d756e3343b71e675 to your computer and use it in GitHub Desktop.
Jenkins Sonar quality gates integration via shared library
#!/usr/bin/env groovy
/**
* Fails the pipeline if project quality doesn't meet the configured quality profile.
* This DSL function must be invoked after the quality analisys has been published.
*
* stage('sonar') {
* steps {
* withSonarQubeEnv('sonar') { //there must be a tool named 'sonar' configured on Jenkins (/jenkins/configureTools)
* sh 'mvn sonar:sonar' //publish project quality on sonar
* }
* }
* }
*
* stage('quality-gates') {
* steps {
* qualityGates() //this stage will fail if project quality doesn't meet its quality profile (see https://docs.sonarqube.org/display/SONAR/Quality+Profiles)
* }
* }
*
*/
def call() {
echo "Iniciando quality gates..."
sh 'sleep 10'
def result = waitForQualityGate()
if (result.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${result.status}"
} else {
echo "Quality gate passed with result: ${result.status}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment