Jira Cloud + ScriptRunner

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')
        .body([
        fields:[
                fixVersions: [[name: epicName]]
        ]
]).asString()

if (result.status == 204) {
    return 'Success'
} else {
    return "${result.status}: ${result.body}"
}
Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply