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

Pipeline retry clause: optionally delay between retries

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I use a retry block to perform requests on a remote server that I don't control (e.g., Apple's Code Signing or Notarization service), and sometimes that remote server is offline.

      Currently retry immediately retries upon failure, so when the remote server is offline for an extended period of time, my pipeline project quickly retries and then the build fails.

      It would be nice to have the ability to make retry wait after each failure, with optional exponential backoff (doubling the wait time after each failure), to give these builds a greater chance of success.  For example:

      retry(tries:5, waitSecondsBetweenFailures:30, doubleWaitTimeAfterEachFailure:true)

        Attachments

          Activity

          Hide
          smokris Steve Mokris added a comment - - edited

          A workaround in the meantime:

              retry(5) {
                  ret = sh returnStatus: true, script: 'some-failure-prone-script'
                  if (ret) {
                      sleep time: 30, unit: 'SECONDS'
                      error 'some-failure-prone-script failed'
                  }
              }
          

          …but there's no way to know when we're on the last retry attempt (see JENKINS-49341), so it unnecessarily waits after the last retry attempt fails.

          Show
          smokris Steve Mokris added a comment - - edited A workaround in the meantime:     retry(5) {         ret = sh returnStatus: true , script: 'some-failure-prone-script'         if (ret) {             sleep time: 30, unit: 'SECONDS'             error 'some-failure-prone-script failed'         }     } …but there's no way to know when we're on the last retry attempt (see JENKINS-49341 ), so it unnecessarily waits after the last retry attempt fails.
          Hide
          broussar Adam Brousseau added a comment -

          in response to the workaround, what about this...?

          ret = false
          retry(5) {
                  if (ret) {
                      sleep time: 30, unit: 'SECONDS'
                  } else {
                      ret = true
                  }
                  sh 'some-failure-prone-script'         
              }
          
          Show
          broussar Adam Brousseau added a comment - in response to the workaround, what about this...? ret = false retry(5) {         if (ret) {             sleep time: 30, unit: 'SECONDS' } else { ret = true } sh 'some-failure-prone-script'             }
          Hide
          asgeirn asgeirn added a comment - - edited

          Here's a different approach:

          timeout(10) {
              waitUntil {
                  script {
                      def r = sh returnStatus: true, script: 'command'
                      return r == 0
                  }
              }
          }
          

          This will retry for up to 10 minutes. waitUntil automatically adds delays between the attempts.

          Show
          asgeirn asgeirn added a comment - - edited Here's a different approach: timeout(10) { waitUntil { script { def r = sh returnStatus: true , script: 'command' return r == 0 } } } This will retry for up to 10 minutes. waitUntil automatically adds delays between the attempts.

            People

            • Assignee:
              Unassigned
              Reporter:
              smokris Steve Mokris
            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: