Created
June 12, 2017 09:27
-
-
Save epishan/9e90efdf3cbb26cb44d99790b120f835 to your computer and use it in GitHub Desktop.
JIRA: Delete inactive workflow without linked schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.jira.component.ComponentAccessor | |
def workflowManager = ComponentAccessor.workflowManager | |
def schemeManager = ComponentAccessor.workflowSchemeManager | |
def sb = new StringBuffer() | |
// get 2 weeks ago date | |
today = new java.sql.Timestamp(new Date().getTime() - 120960000) | |
workflowManager.workflows.each { | |
def schemes = schemeManager.getSchemesForWorkflow(it) | |
if(schemes.size() == 0) { | |
def upd_date=it.getUpdatedDate() | |
if( upd_date < today ) { | |
sb.append("Deleting workflow: ${it.name} \n") | |
try { | |
workflowManager.deleteWorkflow(it); | |
} catch (RuntimeException e) { // EDIT --- Should be Exception, RuntimeException | |
return false | |
} | |
} else { | |
sb.append("SKIPPING ${upd_date} is after ${today} \n") | |
} | |
} | |
} | |
return sb.toString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment