Get Active Sprint from project

Dan27 June 13, 2018

Hi,

I would like to get the active sprint + the 3 older sprints before it, from a project. I write the code with script field.

How can I do it?

Thanks!

3 answers

2 votes
miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Hi Daniel!

It's going to be challenging: sprints are associated with boards, not projects. That being said, a board can be based on a project (all project scope) but you can also have multiple boards for a single project! The idea coming to my mind would be to get the sprint list associated with boards and get the board scope but that's definitely a tricky one!

Hope this helps!

Cheers

Dan27 June 13, 2018

Thanks! I will work on board,

So how can I get the active sprint + the 3 older sprints before it from the board? :)

1 vote
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Hello,

Kidnly have a look at this example:

https://gist.github.com/jechlin/9789183

miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Which is great for active sprint (as long as you have only one) but won't work for the last 3 sprints. Maybe something can be done with Sprint IDs? 

That's definitely the sprintManager which will help and that example is a great start point which will just need a few more tweaks @Dan27 :)

Dan27 June 13, 2018

Hi,

I have errors:

Can't find the functions: getRapidView , getSprintsForView.

I have all of the imports... Do you have any suggestions ?

Like Mikhail Kosenko likes this
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

@Dan27 where do you run the script?

Dan27 June 13, 2018

Script field of Script Runner

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Try first in the Script Console and kindly provide erros

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 = ComponentAccessor.getIssueManager().getIssueObject("your issue key")

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}")
}
Dan27 June 13, 2018

Thank you!

I found only Board key and name, hoe can I find the id ?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

When you open a board, have a look at the url. There must be something like rapidview=<numeric>. This numeric is the id.

Dan27 July 9, 2018

111.png@Alexey Matveev Can you please help me understanding this error ?

0 votes
Dan27 July 10, 2018

Hi @Alexey Matveev and @miikhy ,

I succeed to take the active sprint, now I would like to get the 2 previous sprints.

Do you have an idea how can I do it ?

 

Thanks,

Daniel

Suggest an answer

Log in or Sign up to answer