I would like to call a webhook - when an issue in Jira transitions to a HIGH priority

JDave September 19, 2019

I'm new with Scriptrunner - going to learn it - I am trying to launch a webhook to an external system - when an issue transitions to a HIGH priority - I want it to trigger the webhook.  Using JQL on the webhook does not work due to a few bugs that have been around for a few years.

I know this is wide open - looking for suggestions, ideas .. resources .. 

 

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2019

Use a scriptrunner scripted listener. Using a custom listener, you can define exactly when to call the webhook.

In this case, look at the changelog associated with the event and if the priority was not high but now it is, then you can call your webhook.

You will have to form your webhook data and call manually in code.

 

import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

def constantsManager = ComponentAccessor.constantsManager
def changeLog = event.getChangeLog()
if (changeLog) {
def changeItems = changeHistoryManager.getChangeHistoryById(changeLog.id).changeItemBeans
if( changeItems.any { it.field.equalsIgnoreCase('priority')} ) {
def changeItem = changeItems.find{ it.field.equalsIgnoreCase('priority') }
def oldPriority = constantsManager.getPriorityName(changeItem.from)
def newPriority = constantsManager.getPriorityName(changeItem.to)
//you may need to adjust this based on your exact priority definition and criteria
if(oldPriority.name != 'High' && newPriority.name == 'High'){
//CALL YOUR WEBHOOK HERE
def httpBuilder = new HTTPBuilder(YOURURL)
httpBuilder.request(Method.POST, ContentType.JSON){
headers."your header" = "whatever"
uri.path = "webhook/endpoint"
uri.query = [key:'value',otherKey:'otherValue']
body = [someMap:"Object"]
response.success = { resp, json ->
//do something with the returned json
}
response.failure = { resp, data ->
//do something with the failure response
}
}
}
}
}
JDave October 16, 2019

Thanks .. I'm finally getting some time to start figuring this out 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events