java.lang.NullPointerException:

2022-03-10  本文已影响0人  87d6dc4b11a7

在执行以下流水线时,报错java.lang.NullPointerException: Cannot invoke method timeout() on null object

node('openjdk8') {
    def sonar_home = tool name: 'sonar-scanner-4.6.2'
    withEnv(["PATH+bin=${sonar_home}/bin:/usr/local/bin:/usr/bin:/bin"]) {

        stage('代码审查'){
            withSonarQubeEnv('sonarqube-8.9.6') {
                sh "sonar-scanner -Dsonar.projectKey=myproject -Dsonar.host.url=http://192.168.116.128:9000/"
            }        
        }
        
        stage('阈值判断') {
            ansiColor('vga'){
                echo "阈值判断"
            } timeout(30) { waitForQualityGate abortPipeline: true } 
        }       
    }
}

参考https://stackoverflow.com/questions/50186137/jenkins-pipeline-cannot-invoke-method-stage-on-null-object,需要修改流水线脚本,将timeout()另起一行:

node('openjdk8') {
    def sonar_home = tool name: 'sonar-scanner-4.6.2'
    withEnv(["PATH+bin=${sonar_home}/bin:/usr/local/bin:/usr/bin:/bin"]) {

        stage('代码审查'){
            withSonarQubeEnv('sonarqube-8.9.6') {
                sh "sonar-scanner -Dsonar.projectKey=myproject -Dsonar.host.url=http://192.168.116.128:9000/"
            }        
        }
        
        stage('阈值判断') {
            ansiColor('vga'){
                echo "阈值判断"
            } 
            timeout(30) { waitForQualityGate abortPipeline: true } 
        }       
    }
}
上一篇下一篇

猜你喜欢

热点阅读