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 ..
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
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.