如何在阶段完成成功后失败Jenkins管道阶段状态

gpnt7bae  于 2023-10-17  发布在  Jenkins
关注(0)|答案(1)|浏览(175)

如何失败的Jenkins管道阶段的状态,阶段完成后成功。请帮忙谢谢

def build_job_result = [:]
pipeline {
    agent any
    stages {
        stage('1') {
            steps {
                build_job_result = build job: "jobName", wait: false
            }
        }
        stage('2') {
            steps {
                  def jobName   = build_job_result.getFullDisplayName().split()[0]
                  def jobNumber = build_job_result.number
                  def jobStatus = build_job_result.getStatus()

                  if (jobStatus == failed) {
                     stage('1').status = failed
                   }
                }
            }
        }        
    }
}
ezykj2lf

ezykj2lf1#

一旦你离开了一个阶段,你就不能改变阶段状态AFAIK。更好的选择是将您的Pipeline重构为如下所示。基本上,并行运行您的阶段。

pipeline {
    agent any
    
    stages {
        stage('Parallel Example') {
            parallel {
                stage('1') {
                    steps {
                        build_job_result = build job: "jobName", wait: true
                        if (build_job_result == failed) {
                            error "Build Failed"
                         }
                    }
                }
                
                stage('2') {
                    steps {
                        echo 'Do something else while the job runs'
                    }
                }
            }
        }
        
    }
}

相关问题