Forked from jechlin/AddIssueToCurrentSprint.groovy
Last active
February 24, 2021 07:10
-
-
Save infernalsirius/721022bb860a2394b06b4f72e5da9af7 to your computer and use it in GitHub Desktop.
[Add issue to current Sprint]https://jamieechlin.atlassian.net/wiki/display/GRV/Working+With+JIRA+Agile 3atlassian #jira
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.docs | |
import com.atlassian.greenhopper.service.rapid.view.RapidViewService | |
import com.atlassian.greenhopper.service.sprint.SprintIssueService | |
import com.atlassian.greenhopper.service.sprint.SprintManager | |
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.issue.Issue | |
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean | |
import com.onresolve.scriptrunner.runner.customisers.WithPlugin | |
/** | |
* Configurable section | |
*/ | |
// Enter the name of the board to which you want to add the issue to the first active sprint | |
def rapidBoardId = 2L | |
@WithPlugin("com.pyxis.greenhopper.jira") | |
@JiraAgileBean | |
RapidViewService rapidViewService | |
@JiraAgileBean | |
SprintIssueService sprintIssueService | |
@JiraAgileBean | |
SprintManager sprintManager | |
Issue issue = issue // provided in binding | |
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() | |
def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue() | |
if (! view) { | |
log.warn("No view with this ID found") | |
return | |
} | |
def sprints = sprintManager.getSprintsForView(view).getValue() | |
def activeSprint = sprints.find { it.active } | |
log.debug activeSprint | |
if (activeSprint) { | |
log.info "Adding issue $issue to ${activeSprint.name}" | |
sprintIssueService.moveIssuesToSprint(loggedInUser, activeSprint, [issue] as Collection) | |
} | |
else { | |
log.info ("No active sprints were found for board: ${view.name}") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment