How to get sprints using greenhopper api?

Hello.

I need to get sprint from my class. I tried to use com.atlassian.greenhopper.service.sprint.SprintService, but I coudn't inject it. How can I get spints of project?

Thanks.

3 answers

1 accepted

Unfortunately there is no public service exported for this.

The only safe way to do this would be to get an issue that has that Sprint in its Sprint field, then query the custom field.

Alternatively you could use reflection to get access to the private SprintService you describe above, but because this is a private service we wouldn't recommend it.

Cheers,
Shaun

Hello.

Thank you very much for fast answer!

I am newbie with JIRA and Greenhopper plugins. Could you please assist a bit more. I do not see any trace of "sprint" field in documentation for "issue":

https://developer.atlassian.com/display/JIRADEV/Issue+fields

I am probably missing something and would really appreciate your help.

Thanks.

The REST api can get you the data, but I am not sure within the plugin how to handle the authentication.

E.g. https://jira.atlassian.com/plugins/servlet/restbrowser#/com-pyxis-greenhopper-jira-greenhopper-rest-filter

Check /sprints/{rapidViewId}

Thank you very much - that helped!

/sprints/{rapidViewId} produces something like this:

{"sprints":[{"id":1,"name":"Sprint 1","closed":true},{"id":2,"name":"Sprint 2","closed":false}],"rapidViewId":1}

But the question still remains:
1.What issue field describes which sprint it belongs to?
2.If we know sprint ID - how do we get issues in this sprint?





Get the custom field values of the issue and Sprint is also a custom field as Shaun said. It should give the id as numeric value.

Getting issues in a sprint can be done using a JQL with Sprint = <<id>>, I guess it is the SearchService that will help you to do this.

https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+JIRA+Issue+CRUD+and+Search

Thanks everyone for help!!!

The final working solution is:

1. Get list of issues for the project(see doc at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+JIRA+Issue+CRUD+and+Search)

2. for (Issue issue : issues){
CustomField customField = customFieldManager.getCustomFieldObjectByName( "Sprint" );

// retrieves the custom field value object from the issue
Object customFieldValue = issue.getCustomFieldValue( customField );

// prints value to console
System.out.println( customFieldValue );

}

3. Output prints similar to

* if issue was only in a single sprint:

[com.atlassian.greenhopper.service.sprint.Sprint@1bacc22[name=Sprint 1,closed=true,startDate=2
012-10-02T08:47:07.160-04:00,endDate=2012-10-05T08:47:00.000-04:00,completeDate=2012-10-04T10:04:47.556-04:00,id=1]]

*if issue has been moved from sprint to sprint (not sure if this is an issue or done in purpose by jira):

[com.atlassian.greenhopper.service.sprint.Sprint@1bacc22[name=Sprint 1,closed=true,startDate=2
012-10-02T08:47:07.160-04:00,endDate=2012-10-05T08:47:00.000-04:00,completeDate=2012-10-04T10:04:47.556-04:00,id=1], com.atlassian.greenhopper.service.sprint.Sprint@186cee5[name=Sprint 2, closed=false,startDate=2012-10-04T10:05:37.479-04:00,endDate=
2012-10-18T10:05:37.479-04:00,completeDate=<null>,id=2]]

Thx for posting, I was having the same problem. I have been trying to cast the Sprint object from the custom field value (array of sprints). However, I get a ClassCastException. I made sure the greenhopper jar was added to my plugin, but it still says it cannot cast:

com.atlassian.greenhopper.service.sprint.Sprint to com.atlassian.greenhopper.service.sprint.Sprint

I even tried to get the at the getters using reflection but that failed. Finally as a work around I just parsed the toString output (yuck). Were you ever able to cast the Sprint object?

Nevermind. Looks like the group ID for the greenhopper has changed com.atlassian.plugins

with the artifactID jira-greenhopper-plugin

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 21, 2018 in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

1,009 views 7 17
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