Ensuring Epics are only closed when Stories are complete

Veera rdy December 4, 2017

Hello,
I need to Ensure Epics are only closed when Stories are complete. I'm using a blocking condition with the following script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager

// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
// TEsting only
Issue issue = issueManager.getIssueByCurrentKey("AB-1234")

// Script code for easy log identification
String scriptCode = "Check all stories closed -"

// Setup the log and leave a message to show what we're doing
Logger logger = log
logger.setLevel( Level.ERROR )
logger.debug( "$scriptCode Triggered by $issue.key" )

passesCondition = true
if (issue.issueType.name == 'Epic')
{
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def found = issueLinkManager.getOutwardLinks(issue.id).any
{
it?.destinationObject?.getStatusObject() != 'Closed'
}
logger.debug( "$scriptCode Found = $found " )
if (found) {
logger.debug( "$scriptCode return false" )
passesCondition = false
} else {
logger.debug( "$scriptCode return true" )
passesCondition = true
}
}
// Always allow all other issue types to execute this transition
else
{
logger.debug( "$scriptCode Not Epic return true" )
passesCondition = true
}

 


The script is listed here: http://www.adaptavist.com/w/jira-genius-ensuring-that-epics-are-only-closed-when-stories-are-complete/

The script is evaluate to "false" even if all the stories in epic are closed.

I might be missing something obvious here, please advice.

1 answer

0 votes
rambabu patina
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.
December 5, 2017

Give a try, The values which are right to equals operator need to be surrounded with double quotes.

Ex: if (issue.issueType.name == "Epic")

Suggest an answer

Log in or Sign up to answer