Example scripts
To homepage
Jira

Remove Unused Workflow Schemes
Features
Script consoleCreated 8 month(s) ago, Updated 30 day(s) ago
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.19)

ScriptRunner For Jira (7.10.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.scheme.Scheme
import com.atlassian.jira.workflow.AssignableWorkflowScheme
import com.onresolve.scriptrunner.canned.util.OutputFormatter
// This script is based on https://confluence.atlassian.com/clean/advanced-cleanup-1018789335.html
def workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager()
// Keep a list of all deleted WorkFlowSchemes so we can report them later
List<AssignableWorkflowScheme> deletedSchemes = []
// Keep a list of all errors during deletion so we can report them later
List<Map<String, String>> deletionErrors = []
workflowSchemeManager.assignableSchemes.each { scheme ->
try {
def workflowSchemeIsUnlinked = workflowSchemeManager.getProjectsUsing(scheme).size() == 0
if (workflowSchemeIsUnlinked) {
workflowSchemeManager.deleteScheme(scheme.id)
deletedSchemes.push(scheme)
}
} catch (Exception e) {
deletionErrors.push([schemeName: scheme.name, errorMessage: e.message])
}
}
// MarkupBuilder writes a HTML string to the output, making sure that any special characters in the
// scheme names (or error messages) are represented correctly in HTML.
OutputFormatter.markupBuilder {
h2('Workflow Schemes Report')
!deletedSchemes && !deletionErrors && p('No unused workflow schemes found')
if (deletedSchemes) {
h3('Deleted Unused Workflow Schemes:')
ul {
deletedSchemes.each { scheme ->
li(scheme.name)
}
}
}
if (deletionErrors) {
h3('Errors:')
table(class: 'aui') {
thead {
tr {
th('Screen Scheme Name')
th('Error')
}
}
tbody {
deletionErrors.each { entry ->
tr {
td(entry.schemeName)
td(entry.errorMessage)
}
}
}
}
}
}
Having an issue with this script?
Report it here