Установите нестабильную сборку при сбое гидролокатора качества - PullRequest
0 голосов
/ 15 апреля 2020

У меня очень простой конвейер. Все определено в моих файлах pom. xml и .m2 / settings. xml. Я хочу, чтобы моя сборка была нестабильной на Jenkins при сбое Quality Gate в SonarQube. Вот что я сделал, но у меня есть несколько ошибок, как «ожидаемый}». Кто-нибудь знает, как это работает? Обратите внимание, что часть среды является необязательной. Спасибо.

pipeline {

    agent {
        label "master"
    }

    tools {
        // Note: this should match with the tool name configured in your jenkins instance (JENKINS_URL/configureTools/)
        maven "Maven 3.6.0"
        jdk 'Java 1.8'
    }

    environment {
        // This can be nexus3 or nexus2
        NEXUS_VERSION = "nexus3"
        // This can be http or https
        NEXUS_PROTOCOL = "http"
        // Where your Nexus is running
        NEXUS_URL = "192.168.1.8:8081"
        // Repository where we will upload the artifact
        NEXUS_REPOSITORY = "repository-example"
        // Jenkins credential id to authenticate to Nexus OSS
        NEXUS_CREDENTIAL_ID = "nexus-credentials"
    }

    stages {

        stage ('Initialize') {
            steps {
                sh '''
                echo "PATH = ${PATH}"
                echo "M2_HOME = ${M2_HOME}"
                '''
            }
        }

        stage("mvn clean deploy") {
            steps {
                script {
                    // If you are using Windows then you should use "bat" step
                    // Since unit testing is out of the scope we skip them
                    sh "mvn -B clean deploy"
                }
            }
        }

        stage ("SonarQube check") {
            steps {
                script {
                    sh 'mvn -B sonar:sonar'
                }

                step {                     
                    qualitygate = waitForQualityGate()                     
                    if (qualitygate.status != "OK") {                         
                        currentBuild.result = "UNSTABLE"                     
                    }                 
                }  
            }
        }          
    }         
}

1 Ответ

0 голосов
/ 15 апреля 2020

Вам нужно обернуть материал QualityGate и все внутри блока script, как показано ниже:

stage ("SonarQube check") {
    steps {
        script {
            sh 'mvn -B sonar:sonar'

            qualitygate = waitForQualityGate()                     
            if (qualitygate.status != "OK") {                         
                currentBuild.result = "UNSTABLE"                     
            }                 
        }
    }
}
...