Jira Cloud + ScriptRunner

13 May 2017 in TIL

When working with Jira, we wanted the fixVersion of any ticket to be automatically set based on the fixVersion of it's associated epic. To do this, create a script listener with ScriptRunner that listens to both the Issue Created and Issue Updated events with the following contents:

def epicKey = get('/rest/api/2/issue/' + issue.key).asObject(Map).body['fields']['customfield_10003']
if (!epicKey) {
return false;
def epicFixVersions = get('/rest/api/2/issue/' + epicKey).asObject(Map).body['fields']['fixVersions']
if (epicFixVersions.size() == 0) {
return false;
def epicName = epicFixVersions[0]['name']
def result = put('/rest/api/2/issue/' + issue.key)
.header('Content-Type', 'application/json')
fixVersions: [[name: epicName]]
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"