Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51586

multiple aborts exit declarative post always step

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Jenkins 2.73.3 on Linux (Centos 7).
      All plugins up to date.

      Declarative pipeline runs through its stages. User clicks abort/cancel red button, pipeline drops into post step as expected. Post has an always block. User then clicks abort again (they are impatient), post is executing always, most likely sh commands, and is then terminated. The 2nd abort should be ignored and the post always should be allowed to complete? There is only one block in the post (always). Post always should be allowed to do cleanup (or is there away to turn off the abort signal once it enters the post always?).

          [JENKINS-51586] multiple aborts exit declarative post always step

          Alastair Munro added a comment - - edited

          A bit of googling shows there is a soft kill versus a hard kill. So ideally clicking the red box would generate a soft kill, while a hard kill can be done via listing the console output and clicking on `Click here to forcibly terminate running steps`? If anyone has any tips or things I can try out, please let me know.

          If you wish to reproduce, here is a sample pipeline:

          pipeline {
            agent { label 'master' }
          
            stages {
          
              stage('Stage1') {
                steps {
                  script {
                    println "In stage1"
                    sleep(60)
                  }
                }
              }
          
              stage('Stage2') {
                steps {
                  script {
                    println "In stage1"
                    sleep(60)
                  }
                }
              }
          
            }
          
            post {
              always {
                script {
                  def c = 0
                  println "Testing post stage is interupted"
                  while (c < 3) {
                    println "Interated loop ${c}."
                    sleep(60)
                    c++
                  }
                }
              }
            }
          }
          
          

          Alastair Munro added a comment - - edited A bit of googling shows there is a soft kill versus a hard kill. So ideally clicking the red box would generate a soft kill, while a hard kill can be done via listing the console output and clicking on `Click here to forcibly terminate running steps`? If anyone has any tips or things I can try out, please let me know. If you wish to reproduce, here is a sample pipeline: pipeline { agent { label 'master' } stages { stage( 'Stage1' ) { steps { script { println "In stage1" sleep(60) } } } stage( 'Stage2' ) { steps { script { println "In stage1" sleep(60) } } } } post { always { script { def c = 0 println "Testing post stage is interupted" while (c < 3) { println "Interated loop ${c}." sleep(60) c++ } } } } }

          Andrew Bayer added a comment -

          So I'm waffling on where this should be categorized - my first thought is that it's Declarative, but abort/kill build behavior is actually in workflow-job...but this is really about Declarative's handling of abort/kill. Blech! I'm moving it back to Declarative, but I don't think we're going to change the behavior - abort/kill the build when you're not in post, and yeah, it should continue on to post. But if you abort/kill the build in post, I don't think there should be a guarantee of further execution. What if you're actually trying to kill the post? Basically, with a Declarative Pipeline, abort/kill the build will always kill the current context - so before you enter post, an abort/kill will kill everything before post, while within post, an abort/kill will kill the post and just end the build.

          Andrew Bayer added a comment - So I'm waffling on where this should be categorized - my first thought is that it's Declarative, but abort/kill build behavior is actually in workflow-job ...but this is really about Declarative's handling of abort/kill. Blech! I'm moving it back to Declarative, but I don't think we're going to change the behavior - abort/kill the build when you're not in post , and yeah, it should continue on to post . But if you abort/kill the build in post , I don't think there should be a guarantee of further execution. What if you're actually trying to kill the post ? Basically, with a Declarative Pipeline, abort/kill the build will always kill the current context - so before you enter post , an abort/kill will kill everything before post , while within post , an abort/kill will kill the post and just end the build.

            Unassigned Unassigned
            amunro Alastair Munro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: