How to bulk delete Inactive/Draft workflows

Need to delete more than 100 Inactive/Draft workflows.

Wondering if there is there a automated way to achieve this, via any scripting methods ?

2 answers

If you have the ScriptRunner plugin, the following script will delete all inactive workflows for you, ignoring the "classic' workflow.

import com.atlassian.jira.component.ComponentAccessor

def workflowManager = ComponentAccessor.workflowManager
def schemeManager = ComponentAccessor.workflowSchemeManager

def sb = new StringBuffer()

workflowManager.workflows.each {
    def schemes = schemeManager.getSchemesForWorkflow(it)
    if(schemes.size() == 0) {
        sb.append("Deleting workflow: ${it.name}\n")
        workflowManager.deleteWorkflow(it)
    }
}

return sb.toString()

 

Note this will not delete inactive schemes, only inactive workflows.  Modifying this to find inactive schemes should be possible.

A quick note: system default workflow should be assigned to some scheme, otherwise script won't work.

Thank you so much.
It work for me using Yevgen suggestion.

 

Unfortunately ScriptRunner is no longer free, but has gone commercial / expensive, so many people can't follow the suggestion. 

 It's frustrating to Admins and harmful to Atlassian's reputation that so many problems (including some horrible spots in the UI, such as this Delete Workflow UI or the user picker) can only be solved by spending a lot of money on plugins.

I definitively agree with you!

Hi Jeff, 

This is of really good help! Thank you!

Can you please let me know if using the below line instead of delete phrase in the script would help me just list the inactive workflows?

 

workflowManager.findWorkflow(it)

 

Thanks

 

The following snippet should work to delete all inactive workflow schemes.  Coupled with the script above, it should clean things up:

 

import com.atlassian.jira.component.ComponentAccessor

def schemeManager = ComponentAccessor.workflowSchemeManager

def sb = new StringBuffer()

schemeManager.schemeObjects.each {
try{
if(schemeManager.getProjectsUsing(schemeManager.getWorkflowSchemeObj(it.id)).size() == 0) {
sb.append("Deleting workflow scheme: ${it.name}\n")
schemeManager.deleteScheme(it.id)
}
}
catch(Exception e) {
//noop
sb.append("Error: " + e + "\n");
}
}

return sb.toString()

Both scripts work like a charm, cleaning up the workflows and the Worflow Schemes.

For some reason one of my workflows cannot be deleted. The logs shows that is it assigned to a scheme eventhough it`s not anymore. So i had to add the "catch exception" to the script to bypass it.

Hey Bill,

I'm trying to edit these excellent scripts to bulk delete other schemes like issue type, issue type screen scheme, got stuck, can you plz help with other bulk delete scripts too

https://community.atlassian.com/t5/Adaptavist-questions/How-to-bulk-delete-screen-schemes-or-issue-type-schemes/qaq-p/712428

Thank you

Hey Jeff Ward 

When I tested bulk delete inactive workflows, got this error

Associated default workflow to other workflow schemes too

Workflow error.png

Well I do it the way that Atlassian might not suggest: directly on the database itself. There is a table call Workflow_Draft (or something like that ) that I can just run a delete statement and then I just reindex the whole JIRA and restart the program. It works for me (in 4.4.1). But again, anything directly to database is not recommended, I guess I have just been lucky.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot