How do I write a groovy expression for my workflow post-function? (Only run transition when all stories of the epic = "Done")

Erez Marcovich February 17, 2016

Hi All,

i am new to groovy. can someone help me with a script for post function that will do the following.

when moving story to done, change the story parent epic to done as well if all the stories that belong to the parent epic are also in done.

thanks in Advanced,

Erez

1 answer

0 votes
Boris Georgiev _Appfire_
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.
February 18, 2016

Here're the steps:

  1. Add post-function to transition the issue
  2. In the post function check if all the stories of the parent epic are done - use JQL to find these stories
  3. If the condition is true execute the code to transition the issue

Use the samples below to construct your own script.

 

Sample of running JQL query and iterating the results:

Use this to create a check of all stories in epic are Done. The JQL should be something like

"Epic Link" = issue.parent.key
package examples.docs
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
 
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
 
// edit this query to suit
def query = jqlQueryParser.parseQuery("project = JRA and assignee = currentUser()")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
 
results.getIssues().each {documentIssue ->
    log.debug(documentIssue.key)
 
    // if you need a mutable issue you can do:
    def issue = issueManager.getIssueObject(documentIssue.id)
    // do something to the issue...
    log.debug(issue)
}

 

Sample on how to transition issue with groovy

Use the com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtil helper to transition the parent if the condition is true

/**

     * Transitions the issue. If it fails, the errorCollection should have some deep validation on why it failed, but this is also logged

     *

     * @param additionalScript

     * @param theIssue

     * @param actionId

     * @param user

     * @param scriptParams

     * @return an IssueResult

     */

    public static IssueService.IssueResult actionIssueWithFeedBack(String additionalScript, MutableIssue theIssue, Integer actionId, User user, Map scriptParams = [:]) {

Suggest an answer

Log in or Sign up to answer