title: Retry and timeout in Jenkins DSL Pipeline job
body: <p>I have a logic for deployment on certain environment that I need to retry. And that logic have some timeout too. So I wrote the DSL code as below:</p>
  <pre><code>     Pipeline {
        stages {
         stage('Promote To Stage2 Environment') {
            options {
              timeout(time: &quot;${env.STAGE_TIME_OUT}&quot;, unit: &quot;HOURS&quot;)
              retry(&quot;${env.RETRY_COUNT}&quot;)
            }
            steps {
              script {
                //my logic
              }
           }
         }
       }
     }
  </code></pre>
  <p>Now , I need to perform rollback action and need to terminate pipeline job, in case retry exceeded or timeout exceeded while doing deployment on particular environment. So I modified the code as below:</p>
  <pre><code>  pipeline {
      stages {
        stage('Promote To Stage2 Environment') {
            steps {
              script {
                try {
                  timeout(time: &quot;${env.STAGE_TIME_OUT}&quot;, unit: &quot;HOURS&quot;) {
                    retry(&quot;${env.RETRY_COUNT}&quot;) {
                      //my logic
                      }
                    }
                  }
                } catch (err) {
                  //Need rollback. action to be required , in case retry exceeded or timeout happen
                  performRollBack('env')
                  error('Deployment on Stage1 failed..... Build rolled back....')
                }
              }
            }
          }
      }
      
  </code></pre>
  <p>Is this is a right way, or something I am missing.</p>