Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
titleWait for Quality Gate under Maven (declarative)
pipeline {
    agent any
    stages {
        stage('SCM') {
            steps {
                git url: 'https://github.com/foo/bar.git'
            }
        }
        stage('build && SonarQube analysis') {
            steps {
				// Optionally use a Maven environment you've configured already
                withMaven(maven:'Maven 3.5') {
                    sh 'mvn clean install'
                }
            }
        }
        stage('SonarQube analysis') {
            steps {
                withMaven(maven:'Maven 3.5') {
                    withSonarQubeEnv('My SonarQube Server') {
                        // requires SonarQube Scanner for Maven 3.2+
                        sh 'mvn package sonar:sonar'
                    }
                }
            }
        }
        stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
					// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
					// true = set pipeline to UNSTABLE, false = don't
					// Requires SonarQube Scanner for Jenkins 2.7+
                    waitForQualityGate abortPipeline: true
                }
            }
        }
    }
}