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

    Details

    • Epic Link:
    • Sprint:
      Blue Ocean 1.2, Blue Ocean 1.3
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            philster_jenkins Phil Clay added a comment -

            When aborting via the old UI, the console log and build page both show one "Aborted by admin" message.

            When aborting via the Blue Ocean UI, the console log and build page both show two "Aborted by admin" messages.

            So, it's like the blue ocean ui is aborting twice. (Note that I can confirm that I did NOT double click the stop button in the blue ocean UI)

            Show
            philster_jenkins Phil Clay added a comment - When aborting via the old UI, the console log and build page both show one "Aborted by admin" message. When aborting via the Blue Ocean UI, the console log and build page both show two "Aborted by admin" messages. So, it's like the blue ocean ui is aborting twice. (Note that I can confirm that I did NOT double click the stop button in the blue ocean UI)
            Hide
            philster_jenkins Phil Clay added a comment - - edited

            Looks like the incorrect behavior from Blue Ocean is caused by this loop.

            Perhaps it could be solved by simply moving the stoppableRun.stop() call to outside of the loop (before the loop starts).  AFAIK, Blue Ocean should not repeatedly abort the job.

            Show
            philster_jenkins Phil Clay added a comment - - edited Looks like the incorrect behavior from Blue Ocean is caused by this loop . Perhaps it could be solved by simply moving the stoppableRun.stop() call to outside of the loop (before the loop starts).  AFAIK, Blue Ocean should not repeatedly abort the job.
            Hide
            philster_jenkins Phil Clay added a comment -

            PR 1321 created

            Show
            philster_jenkins Phil Clay added a comment - PR 1321 created
            Hide
            jamesdumay James Dumay added a comment -

            Thanks Phil Clay. Ill have Vivek Pandey review this next week.

            Show
            jamesdumay James Dumay added a comment - Thanks Phil Clay . Ill have Vivek Pandey review this next week.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: