Skip to content

Instantly share code, notes, and snippets.

@elonmusk408
Forked from rmpestano/qualityGates.groovy
Created February 25, 2021 10:44
Show Gist options
  • Save elonmusk408/c73d2bc2e67bb9e6d756e3343b71e675 to your computer and use it in GitHub Desktop.
Save elonmusk408/c73d2bc2e67bb9e6d756e3343b71e675 to your computer and use it in GitHub Desktop.

Revisions

  1. @rmpestano rmpestano revised this gist Apr 12, 2018. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -20,13 +20,14 @@
    *
    */
    def call() {
    echo "Initializing quality gates..."
    sh 'sleep 10' //small delay because project quality can still being published on previous stage (specially on bigger projects).
    def result = waitForQualityGate() //this is enabled by quality gates plugin: https://wiki.jenkins.io/display/JENKINS/Quality+Gates+Plugin
    if (result.status != 'OK') {
    error "Pipeline aborted due to quality gate failure: ${result.status}"
    } else {
    echo "Quality gate passed with result: ${result.status}"
    timeout(time: 3, unit: 'MINUTES') {
    echo "Initializing quality gates..."
    sh 'sleep 10' //small delay because project quality can still being published on previous stage (specially on bigger projects).
    def result = waitForQualityGate() //this is enabled by quality gates plugin: https://wiki.jenkins.io/display/JENKINS/Quality+Gates+Plugin
    if (result.status != 'OK') {
    error "Pipeline aborted due to quality gate failure: ${result.status}"
    } else {
    echo "Quality gate passed with result: ${result.status}"
    }
    }

    }
  2. @rmpestano rmpestano revised this gist Apr 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env groovy

    /**
    * Fails the pipeline if project quality doesn't meet the configured quality profile (see https://docs.sonarqube.org/display/SONAR/Quality+Profiles).
    * Fails the pipeline if project quality doesn't meet the configured quality profile (see https://docs.sonarqube.org/display/SONAR/Quality+Gates AND https://docs.sonarqube.org/display/SONAR/Quality+Profiles).
    * This DSL function must be invoked after the quality analisys has been published. Example:
    *
    * stage('sonar') {
  3. @rmpestano rmpestano revised this gist Apr 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    /**
    * Fails the pipeline if project quality doesn't meet the configured quality profile (see https://docs.sonarqube.org/display/SONAR/Quality+Profiles).
    * This DSL function must be invoked after the quality analisys has been published.
    * This DSL function must be invoked after the quality analisys has been published. Example:
    *
    * stage('sonar') {
    * steps {
  4. @rmpestano rmpestano revised this gist Apr 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    def call() {
    echo "Initializing quality gates..."
    sh 'sleep 10' //small delay because project quality can still being published on previous stage (specially on bigger projects).
    def result = waitForQualityGate()
    def result = waitForQualityGate() //this is enabled by quality gates plugin: https://wiki.jenkins.io/display/JENKINS/Quality+Gates+Plugin
    if (result.status != 'OK') {
    error "Pipeline aborted due to quality gate failure: ${result.status}"
    } else {
  5. @rmpestano rmpestano revised this gist Apr 2, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env groovy

    /**
    * Fails the pipeline if project quality doesn't meet the configured quality profile.
    * Fails the pipeline if project quality doesn't meet the configured quality profile (see https://docs.sonarqube.org/display/SONAR/Quality+Profiles).
    * This DSL function must be invoked after the quality analisys has been published.
    *
    * stage('sonar') {
    @@ -14,7 +14,7 @@
    *
    * 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)
    * qualityGates() //this stage will fail if project quality doesn't meet its quality profile
    * }
    * }
    *
  6. @rmpestano rmpestano revised this gist Apr 2, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,8 @@
    *
    */
    def call() {
    echo "Iniciando quality gates..."
    sh 'sleep 10'
    echo "Initializing quality gates..."
    sh 'sleep 10' //small delay because project quality can still being published on previous stage (specially on bigger projects).
    def result = waitForQualityGate()
    if (result.status != 'OK') {
    error "Pipeline aborted due to quality gate failure: ${result.status}"
  7. @rmpestano rmpestano created this gist Apr 2, 2018.
    32 changes: 32 additions & 0 deletions qualityGates.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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}"
    }

    }