I noticed that in my Jenkins pipeline, cloning a git repo automatically times out after 10 minutes. According to the Jenkins pipeline documentation and another Stack Overflow question, you can set the timeout by using a timeout
step or by adding timeout
to your pipeline options.
My Jenkinsfile.groovy
contains the following:
timeout(time: 60, unit: 'MINUTES') {
dir('repo-name') {
git branch: 'branch-name', url: 'https://github.com/repo-name.git'
}
}
But when I run the Jenkins job, the command times out after 10 minutes. I checked the console, and when the repo was being cloned, it showed a comment # timeout=10
.
Why didn't the timeout change here?
After many frustrating hours of troubleshooting, I discovered that Jenkins has a handy groovy snippet generator: if you're hosting Jenkins on http://localhost:8080, just go to http://localhost:8080/pipeline-syntax and you can plug in any step to get the same functionality in groovy script format.
Using this tool, I generated an entirely different command to clone the repo:
checkout([
$class: 'GitSCM',
branches: [[name: 'branch-name']],
extensions: [[$class: 'CheckoutOption', timeout: 60]],
userRemoteConfigs: [[url: 'https://github.com/repo-name.git']],
])
I'm guessing that in my Jenkins, the default git checkout timeout was set to 10 minutes at some point, and this command is the only way to change it.