It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get Sprint name and ID from Issue object when writing plugin?

I'm trying to get the Sprint Name and ID from the sprint that an issue is assigned to in my plugin that i am writing. I first tested some of this functionality in the Script Runner plugin using the script console in a Groovy script, but apparently that is a little more flexible than Java.

Here's what i had working in a Groovy script:

CustomField sprint = customFieldManager.getCustomFieldObjectByName("Sprint")

So, i had to access it like a list because that's apparently what is returned. This doesn't work very well in a plugin, and my plugin won't compile. Has anyone accessed this information like this and if so, can you please share how that is accessed? Thanks.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted

Thank you very much for the answer. Here is the complete picture:

In pom.xml:


        <!-- TestKit version 5.x for JIRA 5.x, 6.x for JIRA 6.x -->

Then in my java class:

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

CustomField sprint = customFieldManager.getCustomFieldObjectByName("Sprint");
ArrayList<Sprint> sprints = (ArrayList<Sprint>)sprint.getValue(issue);

Obviously this is shortened a bit, but at least it's the whole picture in one place

The way to do all this is actually a bit tricky. Atlassian has a Manager class called SprintManager, which will provide you all kind of functions around Agile's sprints.

However, it is not an easy to find interface, so you have to dig a little to get it:

def greenhopperContext = GetApplicationContext("com.pyxis.greenhopper.jira");
def sprintManager = greenhopperContext.getBean("sprintManagerImpl");

It doesn't look like that is going to get me what I want. According to the SprintManager API, it only gives me ways of dealing with sprints directly (creating, deleting, updating, etc.). So, I would need to already know the sprint ID or name prior to looking up the sprint with the manager. I want to somehow get that information from the issue. So i start with an issue, and then get the sprint information. Do you know of a way to do this?

Here is a link to the SprintManager API documentation from JIRA Agile

Ok, seems like I misread your question a little.Hopefully I get it right this time:

public Long getSprintId(){
	ArrayList<Sprint> list = (ArrayList<Sprint>) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint").getValue(getIssue());
		Iterator<Sprint> it = list.iterator();
		Sprint current = null;
		        Sprint next =;
			if(current .getId()<next.getId()){
		return current;
		//do something else

Unfortunatly its just some Java code, but it should not be to hard to translate it into Groovy.

After you run this code you will get the last valid Sprint your issue was in.

Ok, i see that you are using Sprint as an object, i'm not sure how to use that as I haven't been able to import any of the Greenhopper(Agile) stuff. Can you explain how to got the ability to use the Sprint object type?

You should get full access to all Agile classes once you added it to the dependencies of your plugin. Just add


to your pom file and rebuild your eclipse project using the command atlas-mvn eclipse:eclipse and you should be ready to go

I converted my comment to an answer so that I can mark both as answers so that others can see the whole picture in one place.

Community showcase
Posted in Europe

Chris Cooke, Tom Harris, Old Street Solutions: Video online

Thanks to Tom Harris and Chris Cooke from Old Street Solutions for their intesting demo (No Slides!) about how they provide Jira Reporting for Everyone! They even have a public playground, if you don...

2 views 0 0
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you