是否有可能的方式/插件可以在Jenkins作业被中止时运行后构建脚本。我确实看到后构建插件提供了执行一组脚本的操作,但只能在成功或失败两个选项上运行。
是否有可能的方式/插件可以在Jenkins作业被中止时运行后构建脚本。我确实看到后构建插件提供了执行一组脚本的操作,但只能在成功或失败两个选项上运行。
对于声明式Jenkins pipeline,您可以按照以下方式实现:
pipeline {
agent any
options {
timeout(time: 2, unit: 'MINUTES') // abort on exceeding the timeout
}
stages {
stage('Echo 1') {
steps {
echo 'Hello World'
}
}
stage('Sleep'){
steps {
sh 'sleep 180'
}
}
stage('Wake up'){
steps {
echo "Woken up"
}
}
}
// this post part is executed if job is aborted
post {
aborted {
script{
echo "Damn it. I was aborted!"
}
}
}
}
always
、unsuccessful
和 cleanup
条件中的指令也会被执行。 - Joman68try {
build here
}catch(FlowInterruptedException interruptEx){
catch exception here
} finally {
postBuild(parameters)
}