[JIRA] Bulk deleting pojects like a boss!

These days I’m working on a JIRA project which may require working with XML backups and project import tool. The JIRA instance I’m currently working on has over one million issues in thousands of projects (including defunct) – that collectively make the XML backup gigantic.

Have you ever come across the situation where you want to delete some of the projects in JIRA to reduce the size of XML backup? Well, here’s a quick script that I wrote. However, it requires the Adaptavist ScriptRunner add-on which is no longer free. 😦

First, delete the index. Shut down JIRA, and then delete everything under <JIRA Home>/caches/indexes directory, and start JIRA again. During the project deletion process, we do not want JIRA to waste time updating the index at each iteration. We get a smaller JIRA instance at the end and we can perform a speedy full re-index later.

Read this script, modify it if necessary, and then copy-paste it into the Script Console.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.permission.ProjectPermissionSchemeHelper;
import com.atlassian.jira.permission.DefaultPermissionSchemeManager;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.bc.project.DefaultProjectService;
import com.atlassian.jira.bc.project.ProjectService;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.util.SimpleErrorCollection;
import com.atlassian.jira.bc.project.ProjectService.DeleteProjectValidationResult;

u = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

psh = ComponentAccessor.getComponent (ProjectPermissionSchemeHelper.class);
dpsm = ComponentAccessor.getComponent (DefaultPermissionSchemeManager.class);
pm = ComponentAccessor.getComponent (ProjectManager.class);
ps = ComponentAccessor.getComponent (DefaultProjectService.class);
a = dpsm.getSchemeObject (10020);
pl = psh.getSharedProjects (a);

log.debug (ps.getClass().getName());
pl.each {
    x ->
        ErrorCollection e = new SimpleErrorCollection();
        log.debug ('Validating ' + x.toString ());
        dpvr =  new ProjectService.DeleteProjectValidationResult (e, x);
        log.debug ('Validated, deleting ' + x.toString ());
    try {
        ps.deleteProject (u, dpvr);
        log.debug ('Deleted ' + x.toString ());
    } catch (Exception ex) {
        log.debug ('Error deleting ' + x.toString ());
        log.debug (ex.getMessage());

This one is written based on the assumption that all the unwanted projects share the same permission scheme. If that is not the case, you can have their keys in an array and modify the above script.

This was tested on JIRA 7.1.1. I am too lazy to go through the web administration console and delete them one-by-one. Hence this script. Enjoy!

PS: If you just copy-paste the above Groovy script without even reading it, then you are dumb as shit.

[JIRA] Bulk deleting pojects like a boss!

2 thoughts on “[JIRA] Bulk deleting pojects like a boss!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s