Skip to content

Instantly share code, notes, and snippets.

@MattLud
Last active February 21, 2018 18:03
Show Gist options
  • Save MattLud/1f8a56fcce933f7e97c366de54c85ba9 to your computer and use it in GitHub Desktop.
Save MattLud/1f8a56fcce933f7e97c366de54c85ba9 to your computer and use it in GitHub Desktop.
Unstick Stuck Docker executor jobs
import hudson.model.labels.*;
node ('master') {
Jenkins.instance.queue.items.each {
//http://javadoc.jenkins-ci.org/hudson/model/Queue.Item.html#isStuck--
//Means that buildable is "starved" and should have already run but no executor is available
//if this is on a docker template, there is no reason it shouldn't have already run.
if(it.stuck && !it.blocked)
{
println("Found stuck job - " + it.task.name + "- checking docker to see if we can unstick")
def label=it.assignedLabel.getName()
Jenkins.instance.clouds.any { dockerCloud ->
def foundTemplate = false;
if(dockerCloud.class.name.equals("com.nirima.jenkins.plugins.docker.DockerCloud"))
{
dockerCloud.templates.each { template ->
template.labelString.split(' ').each{ splitLabel ->
if(splitLabel.equals(label)){
println(dockerCloud.name + " - " + template.labelString + " - provisioning...")
//dockerCloud.provision(new LabelAtom(label),1)
foundTemplate = true
}
}
}
if (foundTemplate)
{
return true
}
return
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment