Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify Job DSL checkout timeout in Jenkins Git plugin?

Clone timeout can be specified using:

git {
    ...
    cloneTimeout(60)
}

where 60 is timeout is minutes. I read that checkout timeout can also be specified but I cannot find details. Both checkoutTimeout(...) and timeout(...) give an error.

EDIT

I can set the checkout timeout via Jenkins GUI (Configuration --> SCM --> Git --> Additional Behaviors --> Advanced Checkout Behaviors --> Timeout). I'd like to do the same in a Groovy script that generates Docker configurations for Jenkins:

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // Add "checkout timeout" here...
        }
        ...
    }
    ...
}
...
like image 388
Petr Vepřek Avatar asked Mar 09 '16 19:03

Petr Vepřek


2 Answers

I had to change it like this with the pipeline as the CheckoutOption was not working for me

extensions: [[$class: 'CloneOption', timeout: 120]]

Full checkout code

checkout([$class: 'GitSCM', branches: [[name: '*/master']],
            extensions: [[$class: 'CloneOption', timeout: 120]], gitTool: 'Default', 
            userRemoteConfigs: [[credentialsId: key, url: repo]]
        ])
like image 109
guillem Avatar answered Oct 19 '22 14:10

guillem


After some experimentation, I found the solution shown below.

RECAP

Checkout timeout can be set via Jenkins GUI (Configuration --> SCM --> Git --> Additional Behaviors --> Advanced Checkout Behaviors --> Timeout). I'd like to do the same in a Groovy script that generates Docker configurations for Jenkins. The script already sets clone timeout.

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // Add "checkout timeout" here...
        }
        ...
    }
    ...
}
...

The obvious

...
// "Checkout timeout"
checkoutTimeout(60)
...

did not work. Setting timeouts in general

...
// "Checkout timeout"
timeout(60)
...

also did not work. Then comment on a web page lead to:

...
// "Checkout timeout"
extensions {
    checkoutOptions {
        timeout(60)
    }
}
...

that also did not work. Finally...

SOLUTION

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // "Checkout timeout"
            configure { node ->
                node / 'extensions' << 'hudson.plugins.git.extensions.impl.CheckoutOption' {
                    timeout 60
                }
            }
        }
        ...
    }
    ...
}
...
like image 8
Petr Vepřek Avatar answered Oct 19 '22 13:10

Petr Vepřek