# 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
Last active
December 30, 2015 04:19
-
-
Save christianchristensen/7775271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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