Bulk delete workflows, screens in JIRA cloud.

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2019

Hi Team,

 

Is there a way we can get a list of unused workflows, workflow schemes, Screens, screen schemes and delete them in JIRA cloud? 

 

Thanks

2 answers

2 votes
cj little July 24, 2021

If you're running Jira Cloud and you'd like to delete all the workflows that Jira is willing to allow you to delete, then consider running the following script in ScriptRunner:

// Get a list of the first N Workflows (appears that N is max of 50)
Map<String, Object> searchResult = get('/rest/api/3/workflow/search')
.queryString("maxResults", "200")
.asObject(Map)
.body

def w = (List<Map<String, Object>>) searchResult.values


// Iterate over all the Workflows; Attempt to delete everyone :eek:
w.each {
if (it.id.entityId != null) {
println "Attempting to delete: ${it.id.entityId} - ${it.id.name}"
def hr = delete('/rest/api/3/workflow/'+ it.id.entityId).asString()
println hr
}
}

If you'd like to delete all the unreferenced Workflow Schemes, try this snippet:

// Get a list of the first 200 Workflow Schemes
Map<String, Object> searchResult = get('/rest/api/3/workflowscheme')
.queryString("maxResults", "200")
.asObject(Map)
.body

def ws = (List<Map<String, Object>>) searchResult.values

// Iterate over all the Workflow Schemes
ws.each {
// Only want the Workflow Schemes without any mappings
if (it.issueTypeMappings.size() == 0) {
println "Deleting: ${it.id} - ${it.name}"
def hr = delete('/rest/api/3/workflowscheme/'+ it.id).asString()
println hr
}
}

I've posted these in my GitHub Repo for forking and updating goodness.

I hope this saves you a couple hundred clicks, hours of your life, and puts a little smile on your face when you are making thankless changes cold and alone in the depths of Jira.  Please enjoy the hours this puts back in your life doing anything other than Jira Administration.  You've earned it.

Brad October 22, 2021

How to modify this for screens and screen schemes?

Like Yanick Schlatter likes this
0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 23, 2019

Hello Ash,

I hope you are having a nice day.

You can use the add-on Script Runner and run the following Script to delete all inactive workflows (Except the default):

import com.atlassian.jira.component.ComponentAccessor

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

def sb = new StringBuffer()

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

You can customize the Script above to delete the schemes you want too.

P.S: System default workflow should be assigned to some scheme, otherwise the script won't work.

For more information about it, please check the question below:

How to bulk delete Inactive/Draft workflow

Let me know if this information helps/

Ash
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2019

@Petter Gonçalves this is the error i see while i'm running the above code.

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor @ line 1, column 1. import com.atlassian.jira.component.ComponentAccessor ^ 1 error at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27) at ConsoleScriptExecution2_groovyProxy.run(Unknown Source)

Ahsan September 1, 2019

@Petter Gonçalves 

Thanks for the script, works perfectly.

Is there any script to delete unused Field Configuration Schemes, Field Configurations and Fields?

Also, Unused Issue Types Schemes and Issue Types.

Thanks in advance. 

Syone Support October 10, 2019

@AshDid you solve that error?

I can't resolve it on jira cloud.

 

Thank you

Manikanta Maram March 25, 2020

I am also receiving the same error . Did any one has any other script for Jira Cloud?

Joshua Lüdeker July 6, 2020

I receive the same error. Anyone knows the reason why?

Moises May 11, 2021

I've seen the same error trying to use this script.

cj little July 24, 2021

The reason I suspect this isn't working for you folks is you are trying to run a script in ScriptRunner that will only work in Jira Server, and you are using Jira Cloud.  :-)

Please see my answer below (on the main thread) that provides a code block that works in Jira Cloud.

Suggest an answer

Log in or Sign up to answer