As an administrator of many different Jira Server/Data Center environments, I try to keep my environment tidy. One of the tasks I most dread is having to clean up discarded Workflow Schemes and Workflows. You know the ones that hide in the Inactive pool. You delete one and then you have to scroll back to the bottom, open the Inactive marker again and delete another one. This can be such a painful process, that many administrators often ignore it, collecting a pile of detritus over time.
To help with this, I wrote the following Groovy script that will clean up all inactive Workflow Schemes and then all of the remaining inactive Workflows. This script was tested with ScriptRunner for Jira. However, it is likely to be able to run with any Groovy script console since it uses just the Jira API.
One last word before I hand you the script. It will delete everything that is marked as inactive. Use this script with extreme caution. You might want to make sure you back up your database before your first run.
I take no responsibility for what happens when you use this script. I make it available for my fellow admins who have suffered long enough with manually cleaning up their old, discarded, dust-gathering artifacts
/*** ** Author: Derek Fields - derek.fields@rightstar.com ** ** Delete all inactive workflow schemes and workflows. Use with EXTREME CAUTION ***/ import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.bc.workflow.WorkflowSchemeService; import com.atlassian.jira.workflow.WorkflowSchemeManager; import com.atlassian.jira.workflow.WorkflowManager; import com.atlassian.jira.workflow.WorkflowScheme; import groovy.transform.Field; @Field WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager() @Field WorkflowSchemeService workflowSchemeService = ComponentAccessor.getComponent(WorkflowSchemeService); @Field WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager(); // Delete all inactive Workflow Schemes def deleteInactiveWorkflowSchemes() { def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); Collection<WorkflowScheme> inactiveWorkflowSchemes = workflowSchemeManager.getAssignableSchemes() .findAll{! workflowSchemeService.isActive((WorkflowScheme) it)} log.warn("Deleted ${inactiveWorkflowSchemes.size()} inactive workflow schemes"); inactiveWorkflowSchemes.each{workflowSchemeService.deleteWorkflowScheme(currentUser, it)} } // Delete all inactive Workflows def deleteInactiveWorkflows() { def active_workflows = workflowManager.getActiveWorkflows() def all_workflows = workflowManager.getWorkflows() def inactiveWorkflows = all_workflows.findAll{!(it in active_workflows)} inactiveWorkflows.each{workflowManager.deleteWorkflow(it)} log.warn("Deleted ${inactiveWorkflows.size()} inactive workflows"); } // First delete the inactive schemes, then delete the inactive workflows deleteInactiveWorkflowSchemes(); deleteInactiveWorkflows();
C_ Derek Fields
Atlassian Practice Manager
RightStar
76 accepted answers
4 comments