美文网首页
java.lang.NullPointerException:

java.lang.NullPointerException:

作者: 87d6dc4b11a7 | 来源:发表于2022-03-10 15:39 被阅读0次

    在执行以下流水线时,报错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 } 
            }       
        }
    }
    

    相关文章

      网友评论

          本文标题:java.lang.NullPointerException:

          本文链接:https://www.haomeiwen.com/subject/vxnfdrtx.html