Multibranch Pipeline: Branch indexing job stuck and cannot be aborted

Article ID:360055870591
1 minute readKnowledge base

Issue

A branch indexing scan job for a multibranch pipeline project has been running for a long time. The job does not respond to abort requests via the Jenkins UI. This is preventing new branches from being discovered. Users are forced to restart their Jenkins instance to cancel the job.

Workaround

This issue was reported in JENKINS-48933. Please contact CloudBees Support so they can collect the necessary data to determine root cause.

As a workaround, the following groovy script can be used to abort branch indexing jobs that have been running for a specified time period.

import groovy.time.TimeCategory /** * Find all branch indexing that have been running for more than the **delay** specified and interrupt them. */ use(TimeCategory) { def delay = 2.hours jenkins.model.Jenkins.instanceOrNull.toComputer().allExecutors .findAll { exec -> exec.elapsedTime > delay.toMilliseconds() exec.currentExecutable != null && exec.currentExecutable instanceof jenkins.branch.MultiBranchProject.BranchIndexing }.each { exec -> println " * Stopping Branch Indexing of ${exec.currentExecutable.parent.fullDisplayName} that spent ${exec.elapsedTime}ms scanning on ${exec.owner.displayName} #${exec.number}..." exec.interrupt(hudson.model.Result.ABORTED, new jenkins.model.CauseOfInterruption() { @Override String getShortDescription() { return "Branch Indexing was running for too long. See Jenkins administrators" } }) } } return