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

pipeline DSL: timeout() does not work if withEnv() is enclosed

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • Jenkins 1.651.1, up-to-date pipeline and workflow plugins (list attached), IBM JRE 1.7.0, Linux

      Pipeline/ workflow DSL: timeout() does not work as expected when a withEnv() is introduced inside the (same) timeout + node blocks and over the (same) shell command.
      Specifically, without the withEnv block, the timeout actually interrupts the shell command.
      With the withEnv block, the timeout does not interrupt the shell command; yet, the build still ends reporting that it was interrupted/ aborted.

          [JENKINS-34637] pipeline DSL: timeout() does not work if withEnv() is enclosed

          Tony Wallace created issue -

          Tony Wallace added a comment - - edited

          This pipeline DSL works as expected: ie, the "sleep" is interrupted at 20 seconds, the timeout exception is caught, the build ends Timeout has been exceeded.

          def err = null
          try{
              timeout(time:20, unit:'SECONDS') {
                  node('chapcs00-ptmp') {
                      sh '''#!/bin/bash -ex
                          sleep 60
                      '''
                  }
              }
          } catch( caughtError ) {
              println 'catch'
              err = caughtError
          } finally {
              println 'finally'
              if(err) {
                  throw err
              }
          }
          
          console output:
          
          Started by user Tony Wallace
          [Pipeline] timeout
          [Pipeline] {
          [Pipeline] node
          Running on chapcs00-ptmp in /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout
          [Pipeline] {
          [Pipeline] sh
          [Z-timeout] Running shell script
          + sleep 60
          Sending interrupt signal to process
          /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout@tmp/durable-28979ffb/script.sh: line 2: 90895 Terminated              sleep 60
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] }
          [Pipeline] // timeout
          [Pipeline] echo
          catch
          [Pipeline] echo
          finally
          [Pipeline] End of Pipeline
          Timeout has been exceeded
          Finished: ABORTED
          

          This DSL script does not work as expected: the sleep runs all the way to 60 seconds. THEN the build ends the same way, Timeout has been exceeded, except timeout did not actually interrupt anything.

          def err = null
          try{
              timeout(time:20, unit:'SECONDS') {
                  node('chapcs00-ptmp') {
                      withEnv(['BLAH=foo',]) {
                          sh '''#!/bin/bash -ex
                              sleep 60
                              : should not be here
                          '''
                      }
                  }
              }
          } catch( caughtError ) {
              println 'catch'
              err = caughtError
          } finally {
              println 'finally'
              if(err) {
                  throw err
              }
          }
          
          console output:
          
          Started by user Tony Wallace
          [Pipeline] timeout
          [Pipeline] {
          [Pipeline] node
          Running on chapcs00-ptmp in /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout
          [Pipeline] {
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] sh
          [Z-timeout] Running shell script
          + sleep 60
          + : should not be here
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] }
          [Pipeline] // timeout
          [Pipeline] echo
          catch
          [Pipeline] echo
          finally
          [Pipeline] End of Pipeline
          Timeout has been exceeded
          Finished: ABORTED
          

          Tony Wallace added a comment - - edited This pipeline DSL works as expected: ie, the "sleep" is interrupted at 20 seconds, the timeout exception is caught, the build ends Timeout has been exceeded . def err = null try{ timeout(time:20, unit:'SECONDS') { node('chapcs00-ptmp') { sh '''#!/bin/bash -ex sleep 60 ''' } } } catch( caughtError ) { println 'catch' err = caughtError } finally { println 'finally' if(err) { throw err } } console output: Started by user Tony Wallace [Pipeline] timeout [Pipeline] { [Pipeline] node Running on chapcs00-ptmp in /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout [Pipeline] { [Pipeline] sh [Z-timeout] Running shell script + sleep 60 Sending interrupt signal to process /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout@tmp/durable-28979ffb/script.sh: line 2: 90895 Terminated sleep 60 [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // timeout [Pipeline] echo catch [Pipeline] echo finally [Pipeline] End of Pipeline Timeout has been exceeded Finished: ABORTED This DSL script does not work as expected: the sleep runs all the way to 60 seconds. THEN the build ends the same way, Timeout has been exceeded , except timeout did not actually interrupt anything. def err = null try{ timeout(time:20, unit:'SECONDS') { node('chapcs00-ptmp') { withEnv(['BLAH=foo',]) { sh '''#!/bin/bash -ex sleep 60 : should not be here ''' } } } } catch( caughtError ) { println 'catch' err = caughtError } finally { println 'finally' if(err) { throw err } } console output: Started by user Tony Wallace [Pipeline] timeout [Pipeline] { [Pipeline] node Running on chapcs00-ptmp in /ptmp/jenkins/chapel-ci/chapcs00-ptmp/workspace/Z-timeout [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] sh [Z-timeout] Running shell script + sleep 60 + : should not be here [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // timeout [Pipeline] echo catch [Pipeline] echo finally [Pipeline] End of Pipeline Timeout has been exceeded Finished: ABORTED

          Tony Wallace added a comment -

          The only difference between scripts with right and wrong behavior is

          withEnv(['BLAH=foo',]) {  }

          was added around the previous shell script

          Tony Wallace added a comment - The only difference between scripts with right and wrong behavior is withEnv(['BLAH=foo',]) { } was added around the previous shell script
          Tony Wallace made changes -
          Description New: Pipeline/ workflow DSL: timeout() does not work as expected when a withEnv() is introduced inside the (same) timeout + node blocks and over the (same) shell command.
          Specifically, without the withEnv block, the timeout actually interrupts the shell command.
          With the withEnv block, the timeout does not interrupt the shell command; yet, the build still ends reporting that it was interrupted/ aborted.

          Tony Wallace added a comment -

          configuration details attached.

          Tony Wallace added a comment - configuration details attached.
          Tony Wallace made changes -
          Attachment New: jenkins.txt [ 32627 ]
          Attachment New: linux.txt [ 32628 ]
          Michael Barrientos made changes -
          Link New: This issue is duplicated by JENKINS-36010 [ JENKINS-36010 ]
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 170807 ] New: JNJira + In-Review [ 184051 ]
          Andrew Bayer made changes -
          Component/s New: pipeline-general [ 21692 ]
          Andrew Bayer made changes -
          Component/s Original: workflow-plugin [ 18820 ]

            jglick Jesse Glick
            hushp1pt Tony Wallace
            Votes:
            9 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: