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

Timeout of stage does not cause build to fail when running PowerShell with bat

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None

      Steps to reproduce

      Run the following declarative pipeline multiple times:

      pipeline {
          agent { label 'windows' }
          stages {
              stage('Stage') {
                  options {
                      timeout(time: 5, unit: 'SECONDS')
                  }
                  steps {
                      script {
                          writeFile(file: 'sleep.bat', text: 'ping -n 100 localhost')
                          writeFile(file: 'sleep.ps1', text: 'Start-Sleep 100')
                          
                          // FAILS 50 %
                          bat 'powershell -File sleep.ps1'
      
                          // OK
                          //bat 'ping -n 100 localhost'
                          
                          // OK
                          //bat 'sleep.bat'
      
                          // OK
                          //powershell 'Start-Sleep 100'
                          
                          // OK
                          //powershell './sleep.ps1'
                      }
                  }
              }
          }
          post {
              always {
                  echo 'always'
              }
              success {
                  echo 'success'
              }
              aborted {
                  echo 'aborted'
              }
              failure {
                  echo 'failure'
              }
              unsuccessful {
                  echo 'unsuccessful'
              }
          }
      }
      
      Expected behavior

      The timeout is honored.
      The build fails on every run.
      The failed builds are displayed "gray".
      In the post actions, "aborted" and "unsuccessful" is echoed.

      Actual behavior

      The timeout is honored.
      The build fails only around 50% of the runs. On about every other run, the build is marked green although it ran into timeout. In these cases, the post actions echo "successful".

      Log of correct gray build:
       

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Stage)
      [Pipeline] timeout
      Timeout set to expire in 5 sec
      [Pipeline] {
      [Pipeline] script
      [Pipeline] {
      [Pipeline] writeFile
      [Pipeline] writeFile
      [Pipeline] batC:\Jenkins\workspace\TimeoutDebug>powershell -File sleep.ps1 
      Cancelling nested steps due to timeout
      Sending interrupt signal to process
      script returned exit code -1
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // timeout
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      always
      [Pipeline] echo
      aborted
      [Pipeline] echo
      unsuccessful
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Timeout has been exceeded
      org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 11ad6797-e9a8-4ec5-80f7-5ac4925f7fd0
      Finished: ABORTED

      Log of incorrect green build:
       

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Stage)
      [Pipeline] timeout
      Timeout set to expire in 5 sec
      [Pipeline] {
      [Pipeline] script
      [Pipeline] {
      [Pipeline] writeFile
      [Pipeline] writeFile
      [Pipeline] batC:\Jenkins\workspace\TimeoutDebug>powershell -File sleep.ps1 
      Cancelling nested steps due to timeout
      Sending interrupt signal to process
      Batchvorgang abbrechen (J/N)? 
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // timeout
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      always
      [Pipeline] echo
      success
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

      Additional information

      I am aware of the "powershell" step and that this is the preferred way of running PowerShell. As you can see in the example pipeline, the bug is not present when using the "powershell" step. Nevertheless I wanted to inform you about this bug, as maybe other executables are affected as well.

            Unassigned Unassigned
            tracetronic TraceTronic GmbH
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: