Jira Cloud + ScriptRunner

This article was published 2 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

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

Thoughts on this post

Leave a comment?