Hello,
I am trying to use scriptrunner to sync JIRA and Statuspage using the API. I am able to get this to work within Automation for Jira using the Webhook action, but I needed to add logic in for multiple components. I took the exact header and body from the working Automation for Jira step but when I try to run it in groovy I can't get past compilation.
Here is the code:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.JSON
def incidentsURL = "https://api.statuspage.io/v1/pages/PAGEID/incidents/"
def http = new HTTPBuilder(incidentsURL)
return http.request(POST, JSON) { req ->
headers."Authorization" = "API_KEY"
body = [
{
"incident": {
"name": "{{issue.summary}}",
"status": "identified",
"metadata": {},
"deliver_notifications": true,
"body": "{{issue.description}}",
"components": {
"COMPONENTID_1": "degraded_performance",
"COMPONENTID_2": "degraded_performance"
},
"component_ids": [
"COMPONENTID_1",
"COMPONENTID_2"
]
}
}
]
response.success = { resp, json ->
assert resp.status == 200
log.debug("My response handler got response: ${resp.statusLine}")
if(htmlText){
return htmlText.getText()
}
else{
return null
}
}
// called only for a 404 (not found) status code:
response."404" = { resp ->
log.error ("Not found")
return null
}
}
I get this error:
Compilation error(s): script_faebee5c347ccee6da33a12299bf286d.groovy: 18: expecting '}', found ':' @ line 18, column 13. "incident": { ^
@Mike Abbe Has it been resolved?
I actually facing a similar issue now
Hi Mike:
In your code you have component_id mentioned twice -
"components": {
"COMPONENTID_1": "degraded_performance",
"COMPONENTID_1": "degraded_performance"
Don't know if that was the cause of your error.
Best, Joseph Chung Yin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.