11

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...
        }
        ...
    }
    ...
}
...
Lee Meador
  • 12,829
  • 2
  • 36
  • 42
Petr Vepřek
  • 1,547
  • 2
  • 24
  • 35

5 Answers5

17

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]]
        ])
guillem
  • 2,768
  • 2
  • 30
  • 44
8

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
                }
            }
        }
        ...
    }
    ...
}
...
Petr Vepřek
  • 1,547
  • 2
  • 24
  • 35
2

How about using the workflow plugin and do something like this?

checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 100]], submoduleCfg: [], userRemoteConfigs: [[]]])
OhadBasan
  • 797
  • 6
  • 15
0

Following checkout config works perfect for me in a jenkins pipeline script. We are using stash1 just like github as internal git server. Replace it with your own.

stage('Checkout') {
            steps {
                echo "Running checkout stage"
                checkout([$class: 'GitSCM', branches: [
                    [name: "*/${params.branch}"]
                ], doGenerateSubmoduleConfigurations: false, extensions: [
                    [$class: 'CleanCheckout'], [$class: 'CloneOption', timeout: 30, shallow: true]
                ], submoduleCfg: [], userRemoteConfigs: [
                    [credentialsId: 'ink_bot', url: "ssh://git@stash1.XYZ.com:7999/int_sparktp/${params.repo}.git"]
                ]])
            }
        }
saumilsdk
  • 721
  • 1
  • 7
  • 17
0

Adding this extension works for me.

extensions: [[$class: 'CloneOption', timeout: 60]]
Neal
  • 82
  • 3