Hi,
Behavior of the below script,
Epic will only be allowed to close if "issues in Epic" are in "completed" state, works without any errors.
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
// 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" )
if (issue.issueType.name == 'Epic')
{
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def foundLinks = issueLinkManager.getOutwardLinks(issue.id)
log.debug(foundLinks.size())
log.info(foundLinks.size())
for (i in foundLinks)
{
def issuelink = i.getIssueLinkType()
if (issuelink.getName() == "Epic-Story Link")
{
def status = i.destinationObject.getStatus().getName()
log.debug(status)
if (i.destinationObject.getStatus().getName() != "Completed")
{
log.debug("Found an open/status issue link")
return false;
}
log.debug("found an epic story link")
}
}
return true;
}
How do I include more status (To Do, Open) apart from completed? I tried "||" and "if" statement no luck.
How to Validate each epic has at least one story and task in "issues in epic" ?
Any help would be appreciated.
-M
For more statuses I'd do something like this:
def statusList = Arrays.asList("Status1", "Status2", "Status3")
if(statusList.contains(i.destinationObject.getStatus().getName())){
.....
}
Multiple issue types can be handled in the same manner.
@Ivan Tovbin Thank you for your input. I am now able to add more status to my script using,
def statusList = Arrays.asList("Completed", "Resolved")
if(!statusList.contains(i.destinationObject.getStatus().getName()))
{
log.debug("Found an open/status issue link")
return false;
However, I would like to add a validator , Every epic should have a Story and a Task under issues epic in order to close the epic.
I tried using below, which doesn't seem to work.
if (foundLinks.size() == 0)
{
return false;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ivan Tovbin Never mind , the if block works. I forgot to publish the workflow.
Thank you for help.
-M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mani Reddy Glad I could help. Please mark this answer as "Accepted" if it resolved your issue.
Cheers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How about a variation on
String mask = “Completed To Do Open”
mask.contains(i.destinationObject.getStatus().getName())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.