Search code examples
jenkinsjenkins-plugins

jenkins: how to graceful remove stuck executor when build and pod are all not exist


How to graceful remove Jenkins stuck executor when:

  1. Jenkins pipeline is running in kubernetes pod via kubernetes Plugin
  2. build was removed due to Build History Rotation config ( automatically )
  3. Kuberentes pod has been removed ( manually )

However, the item still show in Build Executor Status as below

enter image description here

got java.lang.NullPointerException via WorkflowRun.finish

enter image description here


even the build isn't exist anymore, but Executor.isBusy() and Executor.isActive() are all true.

hudson.model.Executor details:

enter image description here

And SubTask.isContinued() also shows true as well.

SubTask ( org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution.PlaceholderTask ) details:

enter image description here


Solution

  • algith, it can be simply "force removed" by kill the executor via:

    jenkins.model.Jenkins.instance
                         .computers.collect { c -> c.executors }
                         .collectMany { it.findAll{ it.isBusy() } }
                         .each { it.interrupt() }
    

    execute in your https://<jenkins.domain.com>/script