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

Cannot execute cleanup sh steps after aborting a scripted pipeline via the Blue Ocean UI

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • blueocean-plugin
    • None
    • Blue Ocean 1.2, Blue Ocean 1.3

      When aborting a scripted pipeline via the Blue Ocean UI (the stop button), jenkins is not allowing my scripted pipeline to execute any "cleanup" sh steps.
      Instead jenkins immediately interrupts any sh steps that occur after the FlowInterruptedException is caught.

      When I abort a build via the old jenkins UI (the red x button), the pipeline is able execute more sh steps after the FlowInterruptedException is caught

      Consider the following simple scripted pipeline:

      try {
          stage ('Do Stuff') {
              timeout(time: 30, unit: 'SECONDS') {
                  // you should abort the build here
                  waitUntil { false }
              }
          }
      } catch (e) {
          stage ('Cleanup') {
              node {
                  echo 'Cleaning up!'
      
                  // This step will fail if the job was aborted via the Blue Ocean UI,
                  // but will succeed if the job was aborted via the old UI
                  sh 'sleep 10'
              }
          }
      }
      

      Aborting a build via the Blue Ocean UI and aborting a build via the old UI result in different behavior in the pipeline.

      When aborting a build via the old UI, the sh step will succeed. This is the desired behavior. Here is the build output:

      Started by user admin
      [Pipeline] stage
      [Pipeline] { (Do Stuff)
      [Pipeline] timeout
      Timeout set to expire in 30 sec
      [Pipeline] {
      [Pipeline] waitUntil
      [Pipeline] {
      [Pipeline] }
      Will try again after 0.25 sec
      
      .. snip ..
      
      [Pipeline] {
      [Pipeline] }
      Aborted by admin
      Will try again after 1.5 sec
      [Pipeline] // waitUntil
      [Pipeline] }
      [Pipeline] // timeout
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Cleanup)
      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test/abort test
      [Pipeline] {
      [Pipeline] echo
      Cleaning up!
      [Pipeline] sh
      [abort test] Running shell script
      + sleep 10
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      Finished: ABORTED
      

      When aborting a build via the Blue Ocean UI, the sh step will fail. Here is the build output:

      Started by user admin
      [Pipeline] stage
      [Pipeline] { (Do Stuff)
      [Pipeline] timeout
      Timeout set to expire in 30 sec
      [Pipeline] {
      [Pipeline] waitUntil
      [Pipeline] {
      [Pipeline] }
      Will try again after 0.25 sec
      [Pipeline] {
      [Pipeline] }
      
      .. snip ..
      
      Aborted by admin
      [Pipeline] // waitUntil
      [Pipeline] }
      [Pipeline] // timeout
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Cleanup)
      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test/abort test
      [Pipeline] {
      [Pipeline] echo
      Cleaning up!
      [Pipeline] sh
      [abort test] Running shell script
      + sleep 10
      Aborted by admin
      Sending interrupt signal to process
      Terminated
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 143
      Finished: ABORTED
      

      This behavior is preventing my scripted pipelines from properly cleaning up on abort.

      We cannot use the Blue Ocean UI because of this.

            philster_jenkins Phil Clay
            philster_jenkins Phil Clay
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: