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

Retry in Declarative options skips retried stages due to earlier failure

XMLWordPrintable

    • Declarative - 1.2, Pipeline - April 2018

      When running the following Pipeline...

      // Keeping the run count
      int runCount = 0
      
      // Main pipeline
      pipeline {
      
          agent any
      
          options {
              retry(3)
          }
      
          stages {
      
              stage('Init') {
                  steps {
                      echo "Init stage"
      
                      script {
                          // Increment the run count
                          runCount++
                      }
      
                      echo "runCount is ${runCount}"
                  }
              }
      
              stage("Foo") {
      
                  steps {
      
                      echo "Stage Foo executing"
      
                      script {
                          if (runCount < 2) {
                              error "Failing - retry me!"
                          } else {
                              echo "Stage Foo will not fail..."
                          }
                      }
                  }
              }
          }
      }
      

      ...the result is that the second, third, etc retries of the Init and Foo stages get skipped "due to earlier failure(s)". That's our standard logic for ensuring that we execute every stage even if there was an earlier failure, to make sure the stage graph is consistent. So we need to do something to ensure that we actually run retried stages regardless.

            abayer Andrew Bayer
            abayer Andrew Bayer
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: