Abort Move/Copy/Promote operation

Article ID:360033317512
2 minute readKnowledge base

Issue

My Move/Copy/Promote operations seems to have hung. It’s been running for hours and I cannot abort it.

Resolution

The operation can be aborted by the following groovy script. Notice that <job or folder name> needs to be replaced with the full name of the item being moved, copied or promoted. Then in the script console of the controller, run:

use(groovy.time.TimeCategory) {
    def delay = 1.hour
    jenkins.model.Jenkins.instanceOrNull.getComputers()
            .each { computer ->
                computer.getAllExecutors().findAll { it.isBusy() }.each { exec ->
                    if (exec.elapsedTime > delay.toMilliseconds()) {
                      if(exec.currentExecutable instanceof com.cloudbees.opscenter.replication.ItemReplicationRecord
                         && exec.currentExecutable.source.fullName=="<job or folder name>") {
                            println " * Aborting ${exec.currentExecutable} that spent ${exec.elapsedTime}ms building..."
//                            exec.interrupt(hudson.model.Result.ABORTED, new jenkins.model.CauseOfInterruption() {
//                                @Override
//                                String getShortDescription() {
//                                    return "Build was suspended for too long. See Jenkins administrators"
//                                }
//                            })
                        }
                    }
                }
            }
}
return

Once you are confident that the script would abort the correct M/C/P operation, uncomment the 6 commented lines and re-run the script to actually abort the operation.

You may need to re-enable the job which was being acted on.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.