I am attempting to define a successful call response from an API and output it to a Jira comment. However, I keep getting the same error message:
2019-06-19 19:58:25,551 http-nio-8080-exec-5 url:/secure/WorkflowUIDispatcher.jspa username:esmith DEBUG esmith 1198x73906x1 1pjq8zi 10.233.231.48,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.j.groovy.groovyrunner.spring] BeforeInstantiation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]
2019-06-19 19:58:25,552 http-nio-8080-exec-5 url:/secure/WorkflowUIDispatcher.jspa username:esmith DEBUG esmith 1198x73906x1 1pjq8zi 10.233.231.48,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.j.groovy.groovyrunner.spring] AfterInitialisation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]
2019-06-19 19:58:25,557 http-nio-8080-exec-5 url:/secure/WorkflowUIDispatcher.jspa username:esmith ERROR esmith 1198x73906x1 1pjq8zi 10.233.231.48,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2019-06-19 19:58:25,558 http-nio-8080-exec-5 url:/secure/WorkflowUIDispatcher.jspa username:esmith ERROR esmith 1198x73906x1 1pjq8zi 10.233.231.48,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TPPI-495, actionId: 61, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script467
at Script467.run(Script467.groovy:23)
My code is here, the main interesting bits are near the bottom:
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import groovyx.net.http.Method
//import static groovyx.net.http.Method.*
import static groovyx.net.http.Method.PATCH
//import static groovyx.net.http.ContentType.JSON
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
Issue sourceIssue = event.getIssueLink().getSourceObject()
Issue issue = event.issue
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CommentManager = ComponentAccessor.getCommentManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ComponentManager = ComponentManager.getInstance()
//Call the School URL field from the ticket
def schoolUrl_field = customFieldManager.getCustomFieldObject("customfield_12456")
// Get the value of the School URL field from schoolURL
def schoolUrl_value = issue.getCustomFieldValue(schoolUrl_field).toString()
//define CNAME entry based on School URL field first octet
def siteName = schoolUrl_value.tokenize(".")[0].toString()
//Define domain based on the School URL field second octet
def siteDomain = schoolUrl_value.tokenize(".")[1].toString()
//Get the value of the Shard field
def shard_field = customFieldManager.getCustomFieldObject("customfield_12454")
// Get the value of the Shard field from schoolURL
def shard = issue.getCustomFieldValue(shard_field).toString()
//Bring them together
def content = "owsoo${shard}.${siteDomain}.com.".toString()
def name = "${siteName}.${siteDomain}.com.".toString()
def dig = "dig ${schoolUrl_value}".execute().text
def comment_success = "School added to DNS \n ${dig}"
def comment_failure = "Adding school to DNS failed. See logs for more info"
def http = new HTTPBuilder("http://[IP_ADDRESS][PORT]/api/v1/servers/localhost/zones/[domain].com")
http.request(PATCH,ContentType.JSON) {
headers."X-API-KEY" = "[API_CALL]"
headers.contentType = "application/json"
body = [
"rrsets": [
[
"name": name,
"type": "CNAME",
"ttl": 300,
"changetype":"REPLACE",
"records": [
[
"content": content,
"disabled": false
]
]
]
]
]
response.failure = { resp, reader ->
[response_failure:resp, reader_failure:reader]
}
response.success = { resp, reader ->
[response_success:resp, reader_success:reader]
}
def response_success = http["response_success"]
def response_fail = http["response_fail"]
def reader_success = http["JSON_success"]
def reader_failure = http["JSON_failure"]
if (response_success == true) {
CommentManager.create(issue, currentUser,comment_success, true)
}
else {
CommentManager.create(issue, currentUser,comment_failure, true)
}
}
What am I doing wrong? I am trying to define a variable in HTTPBuilder, swap it out of HTTPBuilder, and then input it in a comment in the issue that kicked off the post-function