如何跳过詹金斯阶段,如果我的构建是失败的,想要直接跳上破坏阶段?(未解决)(重要)



如果我的构建失败或时间超过,我想跳过詹金斯阶段,想直接跳到破坏阶段我试着

stage('Build') {
options {                                                                                                                                                                   
timeout(time: 10, unit: 'MINUTES')
}
steps {
// Build steps
}
}
// Other stages
}

}但是我无法摧毁我的构建,构建被中止了也试过这个:

pipeline {
agent any
stages {
stage('Stage 1') {
steps {
// Add your stage 1 steps here
}
}
stage('Stage 2') {
steps {
// Add your stage 2 steps here
}
}
// Repeat for stages 3 to 8
stage('Last Stage') {
steps {
// Add your last stage steps here
}
}
}
post {
always {
script {
if (currentBuild.result == 'FAILURE') {
stage('Last Stage') {
// Add your last stage steps here
}
}
}
}
}

但这对我也不起作用

如果得到错误r超时,则无法跳转到销毁阶段

我真正想要的是-这个我想要

您可以添加一个post failure阶段,当到达该阶段时,该阶段将被销毁:

post {
failure {
// destroy steps
}
}

如果构建失败,则必须到达此步骤。但是,如果它因超时而终止,它将不会来到这里。相反,您必须捕获超时错误,并通过以下操作将其转换为失败:

} catch (error) {
println error
failure(message: "Timeout reached.")
}

看看这个问题和它的答案,看看你如何做到这一点。

你也可以把你的销毁逻辑放在一个函数中,并在failureaborted的情况下调用该函数:

def destroy () {
...
}
...
post {
failure {
destroy()
}
aborted {
destroy()
}
}

最新更新