Options in declarative pipeline

stage (‘Build’) {

		options {
        retry(2)
        timeout(time: 10, unit: 'MINUTES')
        
        }
        steps {
           //code
        }
        post {  
            success { 
             //code
            }
        }
    }

In the following jenkins stage… when the timeout is exceeded and when it retires, the timeout doesn’t work. Why does the timeout does not work in the retries?? Is there any other workaround but have it in the options block?

I’m on the same situation.

Have you discovered any workarround?

If I’m not mistaken, the timeout option in the options block applies to the entire stage, including all retries. This means that the timeout is not reset for each retry, but rather applies to the cumulative time of all retries. :thinking:

To have a timeout for each individual retry, I guess you would have to move the timeout block inside the steps block.

Here is an untested example of how you could do it:

stage('Build') {
    options {
        retry(2)
    }
    steps {
        timeout(time: 10, unit: 'MINUTES') {
            // code
        }
    }
    post {  
        success { 
            // code
        }
    }
}

In this configuration, the timeout should apply to each retry individually. :crossed_fingers:

1 Like