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

Better handling of timeouts in pipeline

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline
    • None

      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'
                      }
                  }
              }
          }
      }
      
      

            Unassigned Unassigned
            fabiang Fabian Grutschus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: