Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA Cloud ScriptRunner auto transitioning epic on child issues completion

Nick Breaux
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2019

Hey everyone,

 

We're running into a issue we're having trouble figuring out. We're using a cloud instance of JIRA with Scriptrunner, and we're looking to automatically transition an epic to a Done status when all the children of the epic are also marked as Done.

We've found a lot of examples, but with the Cloud instance of JIRA, we can't run the import lines such as:

import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent

import com.atlassian.jira.event.issue.IssueEvent

import com.atlassian.jira.event.issue.IssueEventBundle

import com.atlassian.jira.event.type.EventType

in the beginning of our scriptlistener.

This is our script now:

"

// Get the Epic Link value from the Issue
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == "Epic Link"
} as Map

def epicKey = issue.fields[customField.id]

// Load the epic
def epic = get("/rest/api/2/issue/${epicKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body

// Get the current status name of the epic
def statusId = epic.fields["status"].id

// If the epic is in "To Do" status, make sure it gets set to In Progress first
if (statusId == "2") {
post("/rest/api/3/issue/${epicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
"transition": [
"id": "21"
]
])
.asString()
}

// Set the epic to Done (Transition id 11)
post("/rest/api/3/issue/${epicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
"transition": [
"id": "11"
]
])
.asString()

return"

 

Which works for a single issue moving over the epic to done, but it doesn't take in count of the other children.

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
July 17, 2019

Hi Nick,

Thank you for your question.

I can confirm that we have created an example of a script located here which can be ran on the script console inside of ScripRunner for Jira cloud to show how you can transition issues returned by a JQL query.

You will be able to use this script as a reference in order to create a script which returns all the children for the Epic in a JQL query and then transitions these issues to the required status.

Please not that when executing a transition a script will only be able to transition the issue,  if the transition to the required status from the current status exists inside of the workflow.

If this issue has solved your requirement can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer