Running a Post Build script when a Jenkins job is aborted

后端 未结 4 1752
执笔经年
执笔经年 2021-02-07 02:23

Is there a possible way / plugin that can run a post build script when a Jenkins job is aborted. I do see that the post build plugin provides an action to execute a set of scrip

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 02:30

    For a declarative Jenkins pipeline, you can achieve it as follows:

    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 {
                echo "Damn it. I was aborted!"
            }
        }
    }
    

提交回复
热议问题