-
-
Save snallami/a17d1a141892b09e27210f6018bf4c5e to your computer and use it in GitHub Desktop.
Kills long running SCM polling threads in Jenkins
This file contains 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.instance.getTrigger("SCMTrigger").getRunners().each() | |
{ | |
item -> | |
long millis = Calendar.instance.time.time - item.getStartTime() | |
if(millis > (1000 * 60 * 60)) // 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(item.getTarget().name) | |
println(item.getDuration()) | |
println(item.getStartTime()) | |
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
Thread.getAllStackTraces().keySet().each(){ item ->
if(item.getName().contains("SCM polling")){ println "Interrupting thread " + item.getId() + " " + item.getName(); item.interrupt() }
}