How do I implement a retry option for failed stages in Jenkins pipelines?

You should be able to combine retry + input to do that
Something like that

stage('deploy-test') {
   try {
     build 'yourJob'
   } catch(error) {
     echo "First build failed, let's retry if accepted"
     retry(2) {
        input "Retry the job ?"
        build 'yourJob'
     }
   }
}

you could also use timeout for the input if you want it to finish if nobody validates.
There is also waitUntil that might be useful but i haven’t used it yet

Edit :
WaitUntil seems definitely the best, you should play with it a bit but something like that is cleaner :

stage('deploy-test') {
   waitUntil {
     try {
       build 'yourJob'
     } catch(error) {
        input "Retry the job ?"
        false
     }
   }
}

By the way, there is doc all of the steps here https://jenkins.io/doc/pipeline/steps

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)