Jenkins基于管道日志在阶段失败

oalqel3c  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(148)

如果cntKO > 0,我想让这个阶段失败,但我只能让构建失败。有没有办法让这个阶段失败?
阶段{

stage('Run the Create users based on Env. defined') {
        options { 
            timestamps () 
            timeout(time: 6, unit: 'HOURS')
        }
        steps {
            
           bat 'python batch\\CloudValidation\\Cloudusercreation-csvfile.py %release%'
           bat "batch\\CloudValidation\\usercreationoncloudnew.bat %ws% %release% %username% %pwd% %tenant% %POD%"
           script{
            def pipeline_log1 = currentBuild.rawBuild.getLog(10000);
            def result1 = pipeline_log1.find { it.contains('Total Number of KO Users') }
            if (result1) {
                   User_KO = result1.split("Total Number of KO Users:")
                   cntko = User_KO[1].toInteger()
                   if (cntko > 0)
                    {
                      echo ('Build failed due to' + result1)
                      **currentBuild.result = 'FAILURE'**
                    }
                }
          
           }
        }
    }
    
   
     stage('xyz) {
        options { 
            timestamps () 
            timeout(time: 6, unit: 'HOURS')
        }
        steps {
            
            bat "batch\\CloudValidation\\CreatePvtCollabSpace.bat 
      
        }
    }

字符串
你能告诉我怎么解决这个问题吗

fafcakar

fafcakar1#

如果您已经能够使构建失败,那么只需捕获错误,并且仅使阶段失败,而不会使整个构建失败。为此,请将steps Package 在catchError中:

steps {
   catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
      ....
   }  
}

字符串

相关问题