Using the following code to write a job to post notifications to Slack I am receiving an error I am not familiar with. Is there a better way to go about this? This code will eventually post notifications to a channel based on a filter for each result in the filter on scheduled intervals. The code is not complete but I am recieving the titled error after running it, although my initial test shows a working result. (Single issue)
I have not yet actually tested in the loop.
The error after run is:
StackOverflowError was thrown during script result serialization to JSON. This error is usually caused by attempt to serialize object graph with cycles. Please convert your script result to serializable object tree.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
log.setLevel(org.apache.log4j.Level.DEBUG)
final webhookPath = '/services/XXXXX' // it-jira-dev
final webhookBase = 'https://hooks.slack.com'
def jiraBaseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("Key in (EDCO-117335)") //"Project = EDCO and Type = Escalation and 'Assigned Team' = 'Software Engineering' and resolution is empty and reporter in membersOf('jira-team-service_desk')")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${search.total}")
search.results.each {documentIssue ->
log.debug(documentIssue.key)
def issue = issueManager.getIssueObject(documentIssue.id)
log.debug("${issue.key}")
//Issue detail augmentation
String summary = issue.summary
String textBlock = "${issue.issueType.name}: <$jiraBaseUrl/browse/$issue.key|${summary}>"
def body = [
text: summary,
blocks: [
[
type: 'section',
text: [
type: 'mrkdwn',
text: textBlock
]
]
]
]
def resp = new RESTClient(webhookBase).post(
path: webhookPath,
contentType: ContentType.HTML,
body: body,
requestContentType: ContentType.JSON
) as HttpResponseDecorator
assert resp.status == 200: "Request failed with status $resp.status. $resp.entity.content.text"
}
Thank you for any help on this!
Hi Steven
This is related to this bug Issue here.
The data returned by your script contains cycles.
See the comment from `Tomasz` on the bug ticket.
Script should return result, which doesn't have cycles in object graph, effectively it must be a tree. This is the common requirement to serialize objects to JSON.
The error you are reporting is the error we added from ScriptRunner 6.16.0 onwards to warn the user that the return type of the job script must be a serializable object tree
In your case, the return type of the script is likely not important anyway, so you can stop this error by just adding null to the last line of the script so its return type is null and it will not try to serialize the cycling object.
Regards
Matthew
@Matthew Clark
Thank you this was the exact problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That looks like perhaps the built-it JSON serializer in the HttpBuilder is getting confused.
I don't know if the RESTClient can work like that, but you can try to serialize the body yourself and send it as plain text.
Something like this
import groovy.json.JsonBuilder
def jsonBody = new JsonBuilder(body).toPrettyString()
def resp = new RESTClient(webhookBase).post(
path: webhookPath,
contentType: ContentType.HTML,
body: jsonBody,
requestContentType: ContentType.TEXT //not sure if you should keep JSON or not
) as HttpResponseDecorator
I've had issues like this where I was successful with serializing then de-serializing ...
def newBody = new JsonSlurper().parseText(new JsonBuilder(body).toString())
In my case, it had turned out to have been a Gstring with fancy interpolation. By adding a toString() in building my body, it resolved it. But the serializing/deserializing issue was a good temporary workaround. I don't see this applying to you since you typed your variable as String.
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.