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

Timeout is caught by the most internal try-catch, but should be caught by the try-catch that surrounds the timeout step

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Simple example:

      node('master') {
        try {
          timeout(time: 5, unit: 'SECONDS') {
            try {
              sleep(30)
            }
            catch (err) {
              echo "For some reason, this catch is activated. Error: ${err.getMessage()}"
            }
            echo "This should not be executed, but it is!"
          }
        }
        catch (err) {
          echo "I expect that this catch will be activated. Error: ${err.getMessage()}"
        }
      }
      

      I expect that when a timeout is reached, the exception will be caught by the try-catch that surrounds the "timeout" step.
      But actually, it is caught by the most inner try-catch.
      My goal here is to set timeout to set of actions and if the timeout is reached, I want them all to stop. I also want to have more try-catch inside for handling other issues.
      But the actual behavior is that when the timeout is reached, the most internal catch handles it instead of the try-catch that surrounds the timeout step.

      This issue is similar to JENKINS-39266. I do not understand why it was closed.

      By the way, the 

      err.getMessage()

      prints "null", which is also a problem.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              erez_arbell Erez Arbell
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: