How to enable timeout in pipeline based on a condition?

14 views
Skip to first unread message

Gajanan Mahajan

unread,
Jun 26, 2020, 7:07:02 AM6/26/20
to Jenkins Users
I've a Jenkins pipeline with following stage -

    stage('Test') {
                options {
                    timeout(time: 5, unit: 'MINUTES')
                }
                steps {
                    script {
                        //some code here
                    }
                }
            }

Here I've set timeout but there will be one parameter say `TimeoutEnabled`. If it has value `true`, only then use timeout restrictions otherwise there will be no timeout restriction for the stage.

How can I handle this efficiently without having duplicated code?

James Nord

unread,
Jun 29, 2020, 5:45:17 PM6/29/20
to Jenkins Users
something like

'timeout(time: ${timeoutEnabled ? 5 : 9999}, unit: 'MINUTES')

Reply all
Reply to author
Forward
0 new messages