Hi Community,
having a working ScriptRunner (Groovy code) script to be executed weekly in a Custom scheduled Job it crashes after executing with error message:
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.
Is there something easy to make it work without the crash of the instance after execution?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
def projectManager = ComponentAccessor.getComponent(ProjectManager)
def userManager = ComponentAccessor.getComponent(UserManager)
def issueService = ComponentAccessor.getComponent(IssueService)
def issueManager = ComponentAccessor.getComponent(IssueManager)
// Get all projects
def projects = projectManager.getProjects()
// Loop through each project
projects.each { project ->
ApplicationUser projectLeadUser = project.getProjectLead()
// Check if the project lead is inactive
if (! projectLeadUser.isActive()) {
// Create an issue in desired Jira project
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setProjectId(Long.valueOf(10126))
issueInputParameters.setIssueTypeId("10002") // Replace with the appropriate issue type ID for JSD
issueInputParameters.setSummary("Inactive Project Lead in Project: " + project.getName())
issueInputParameters.setDescription("The project lead for this project is inactive: " + projectLeadUser.getName())
issueInputParameters.setReporterId("daniel")
issueInputParameters.setComponentIds(Long.valueOf(10120))
CreateValidationResult createValidationResult = issueService.validateCreate(currentUser, issueInputParameters)
if (createValidationResult.isValid()) {
IssueService.IssueResult createResult = issueService.create(currentUser, createValidationResult)
if (createResult.isValid()) {
MutableIssue issue = createResult.getIssue()
// Optionally, you can log the created issue key or perform any additional actions
log.info("Issue created: " + issue.getKey())
} else {
// Handle create issue error
log.error("Error creating issue: " + createResult.getErrorCollection())
}
} else {
// Handle validation error
log.error("Validation error: " + createValidationResult.getErrorCollection())
}
}
}
The script loops through all projects, looks if there is a project lead which is inactive and reports about that project into a Jira project so an administrator can have a look into it.
Many thanks!
Cheers,
Daniel
That might seem simple... but try to just return something at the end of the job.
Like
return null
Or
return "$issueCount issues created" //
What I think is happening is that the "projects.each" closure is the last return statement and the job framework is attempting to serialize that closure to a JSON string which causes either a very deep stack or a self-referencing stack.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.