How can I get a list of empty Folders and Multibranch jobs

Issue

You want to locate Folders/Multibranch jobs that are empty and no longer contains any item inside.

Environment

Resolution

Go to Manage Jenkins > Script Console and copy/paste the following script. It will print the name of all folders and Multibranch jobs with no items inside.

import com.cloudbees.hudson.plugins.folder.Folder
import com.cloudbees.hudson.plugins.folder.AbstractFolder

Jenkins.instance.getAllItems(AbstractFolder.class).each { folder ->
  if (isEmpty(folder)) {
    println folder.fullName + " - " + folder.class
  }
};
  
return
  
def isEmpty(folder) {
  return folder?.items?.size() == 0
}

Have more questions?

0 Comments

Please sign in to leave a comment.