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

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Summit

Find a your Summit 2019 Buddy!

Can you believe there's less than one month until Summit 2019? It's time to start planning your agendas, not to mention packing ... In the meantime, introduce yourselves on this thread so that you ...

237 views 15 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you