Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

JENKINS-5413: SCM polling getting hung

# crontab
0 * * * * jenkins /var/lib/jenkins/threadkillscm.sh >> /tmp/jenkins-threadkillscm.log

# cat /var/lib/jenkins/threadkillscm.sh 
java -jar /var/lib/jenkins/jenkins-cli.jar -s http://myserver:8080/ groovy /var/lib/jenkins/threadkillscm.groovy
jenkins.model.Jenkins.instance.getTrigger("SCMTrigger").getRunners().each()
{
item ->
println(item.getTarget().name)
println(item.getDuration())
println(item.getStartTime())
long millis = Calendar.instance.time.time - item.getStartTime()
if(millis > (1000 * 60 * 3)) // 1000 millis in a second * 60 seconds in a minute * 3 minutes
{
Thread.getAllStackTraces().keySet().each()
{
tItem ->
if (tItem.getName().contains("SCM polling") && tItem.getName().contains(item.getTarget().name))
{
println "Interrupting thread " + tItem.getName();
tItem.interrupt()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment