Ensuring Epics are only closed when Stories are complete

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
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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

276 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you