Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using SprintManager in a ScriptRunner Script

BSCI-SCMNM8-SVC
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 26, 2023

I am attempting to get a list of all sprints that belong to a particular board in a ScriptRunner script. I have been able to use the ProjectManager in the following manner:

'''

Project templateProject = ComponentAccessor.projectManager.getProjectObjByKey("KEY")
'''

However, I am not able to access the SprintManager - I have tried the following formats:
'''
SprintManager sprintManager = ComponentAccessor.getComponent(SprintManager)
'''
--this returns null

and
'''
SprintManager templateSprint = ComponentAccessor.sprintManager
'''
which results in a 
''' java.lang.NoClassDefFoundError: com.atlassian.greenhopper.manager.GreenHopperCache
'''
error.

Is there something I should be doing directly? Is there any documentation that can demonstrate how to get Sprint details using the Java API?

1 answer

1 vote
Hieu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2023

Hi @BSCI-SCMNM8-SVC 

I dont use sprint manager, but the idea is get them from the tickets with JQL filter

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.greenhopper.service.sprint.Sprint

CustomField sprint = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10608")

List<Sprint>results = []

Issues.search('project = ITSMP and Sprint in openSprints()').each { issue ->

    List<Sprint> sprints = (List<Sprint>)issue.getCustomFieldValue(sprint)

    results.addAll(sprints)

}
results.unique().each { s -> log.warn(s.getName() + " Active -> " + s.getState().toString()) }

Results I got:
2023-07-27 03:41:27,060 WARN [runner.ScriptBindingsManager]: CW 27/2023 -> ACTIVE
2023-07-27 03:41:27,060 WARN [runner.ScriptBindingsManager]: CW 21/2023 -> CLOSED
2023-07-27 03:41:27,060 WARN [runner.ScriptBindingsManager]: CW 25/2023 -> CLOSED

 In the results it also includes closed sprints cause some ticket has invoked in many sprint and not finish yet.

Hope it helps!

Suggest an answer

Log in or Sign up to answer