Greenhopper - Howto put an issue into sprint using groovy?

I would like to put an issue into a sprint via a scriptrunner post-action.

My problem is that I cannot access the SprintIssueService. The following code will return sprintIssueService not found:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.plugin.PluginAccessor

// get user and issue
def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = jiraAuthenticationContext.getUser()
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")

// access greenhopper
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class greenHopperClass = pluginAccessor.getClassLoader().findClass("com.pyxis.greenhopper.GreenHopper");
def greenHopper = componentManager.getOSGiComponentInstanceOfType(greenHopperClass);

if (! greenHopper ) {
  return "greeenHopper not found"

// access SprintIssueService
Class sprintIssueServiceClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.service.sprint.SprintIssueService")
def sprintIssueService = componentManager.getOSGiComponentInstanceOfType(sprintIssueServiceClass);

if (! sprintIssueService ) {
  return "sprintIssueService not found"
} else { 
  return sprintIssueService.getSprintsForIssue(user, issue)

Can someone help?

3 answers

1 accepted

0 votes
Answer accepted

As one can only access the sprints via REST api, one has to use some HTTPClient (e.g. org.apache.commons.httpclient.HttpClient) to get it done.

The last post of the following shows a code example of that:

That's sad but I think you are right. The sprintIssueService is not public/exposed and the only way to access it is via REST. So I have to rethink my idea with a post-action :-/

From my experience most of the Service objects from GreenHopper are not exposed to other plugins. You'd be best attempting to do it via the REST interface. Not that GH has a published REST interface but you can discover it fine using the Developer Tools plugin and REST browser in that.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 6 hours ago in United States

Atlassian acquires AgileCraft

         Good Day, Bad bad traffic, not sure why!!!! 1/2 hour commute took me 2 hours today 🤯 What helped me is that I kept browsing LinkedIn until...

29 views 1 0
View post

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