Better handling of timeouts in pipeline

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Hello,

      currently there is now way to catch timeouts in declarative pipelines explicitly. I usually assume those are errors, since the timeout is either to low or something is wrong in the pipeline.

      Either turn them into an failure:

      pipeline {
          agent any
          
          options { 
              timeout(time: 1, unit: 'MINUTES', buildResult: 'FAILURE')
          }
      
          stages {
              stage('Hello') {
                  steps {
                      echo 'Hello World'
                  }
              }
          }
          
          post {
              failure {
                  println 'Oops, we failed'
              }
          }
      }
      

      Or allow catching them is post{}:

      pipeline {
          agent any
          
          options { 
              timeout(time: 1, unit: 'MINUTES')
          }
      
          stages {
              stage('Hello') {
                  steps {
                      echo 'Hello World'
                  }
              }
          }
          
          post {
              timeout {
                  println 'Oops, we timed out'
              }
          }
      }
      
      pipeline {
          agent any
      
          stages {
              stage('Hello') {
                  options { 
                      timeout(time: 1, unit: 'MINUTES')
                  }
          
                  steps {
                      echo 'Hello World'
                  }
                  
                  post {
                      timeout {
                          println 'Oops, we timed out'
                      }
                  }
              }
          }
      }
      
      pipeline {
          agent any
      
          stages {
              stage('Hello') {
                  steps {
                      timeout(time: 1, unit: 'MINUTES') {
                          echo 'Hello World'
                      }
                  }
                  
                  post {
                      timeout {
                          println 'Oops, we timed out'
                      }
                  }
              }
          }
      }
      
      

            Assignee:
            Unassigned
            Reporter:
            Fabian Grutschus
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: