how automatically start and stop sprints same day every week

Tomas Arguinzones Yahoo December 14, 2016

Hi...I need some guidance about whether it is possible to automatically start and stop our sprints without any manual intervention. All our sprints start Thursday and end Wednesday the following week. Can something like that be accomplished with scriptrurner? Our JIRA instance is a Data Center instance with 2 nodes, version 7.1.4. Scriptrunner is 4.3.13

 

Thank you for your assistance

 

4 answers

1 accepted

3 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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.
December 15, 2016

Hi Tomas,

Interesting question / automation smile

Probably you will need one or two ScriptRunner Service running a script every <Choose day>. The script for closing a sprint should be something like 

import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.pyxis.greenhopper.jira")
def sprintServiceOutcome = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager).getAllSprints()

if (sprintServiceOutcome.valid) {
    sprintServiceOutcome.getValue().findAll { it.state == Sprint.State.ACTIVE }?.each { updateSprintState(it, Sprint.State.CLOSED) }
}
else {
    log.error "Invalid sprint service outcome, ${sprintServiceOutcome.errors}"
}

def updateSprintState(Sprint sprint, Sprint.State state) {

    def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)
    def newSprint = sprint.builder(sprint).state(state).build()
    def outcome = sprintManager.updateSprint(newSprint)

    if (outcome.isInvalid()) {
        log.debug "Could not update sprint with name ${sprint.name}, ${outcome.getErrors()}"
    } else {
        log.debug "${sprint.name} updated."
    }
}

So the above script is a guide on how to update sprints. I suppose it will require some more logic, but you can build on this. Please let me know if you need further assistance.

regards, Thanos

Tomas Arguinzones Yahoo December 15, 2016

Hello Thanos...thank you for your reply...thats great!

I kinda get the logic behind that script but I do have a couple of questions. The idea is that the script has to "loop" and find all active sprints and close them so I dont see any looping in that script. And the sprint names change every week so I see in that script def SPRINT_NAME = "Sample Sprint 2", but I cant put a fix sprint name, can I? The sprint names change every week and the script should find all active sprints and close them the day the script runs, thats the idea.

 

Thank you very much for your help

 

 

 

Thanos Batagiannis _Adaptavist_
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.
December 15, 2016

Hey Thomas, 

I updated the script above in order to close all the active sprints. 

The script to make active future sprints should be very similar. You will need to 'play' with the states.

Tomas Arguinzones Yahoo December 16, 2016

Hi Thanos...thank you very much for your help.

I will give it a try and let you know how it went. 

Thank you

Tomas Arguinzones Yahoo January 17, 2017

Hi Thanos...I just wanted to let you know that I was able to test the script to automatically close all active sprints and it worked as a charm! Thank you very much for your assistance.

I will try to create one to activate future sprints and let you know if I have any questions.

 

Thanks a lot for your help!

Tomas Arguinzones Yahoo January 26, 2017

Hi there...I have a question regarding this script....how can I see the sprints that were closed when the script runs? is there any log I can check to see if the script ran, if there were any issues, and the sprints that were closed?

 

Thank you

Thanos Batagiannis _Adaptavist_
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.
February 17, 2017

hi Tomas,

You can add in the each closure a debug message

log.debug "Issue key to be updated : ${it.key}"

And then you can check your Atlassian logs. First you have to set the debugging level for JIRA to DEBUG

Yogesh Mude
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.
April 2, 2019

Hey @Thanos Batagiannis _Adaptavist_ 

Thanks for the above script...as you mentioned in your comment we need to add a service and it will run at regular basis to close the sprint.

We are looking like whenever the sprint close/complete date will reach the sprint should auto close.

Meghan Stovall September 13, 2021

Hi @Thanos Batagiannis _Adaptavist_ 

I am trying to use this script to auto stop and start sprints. I am extremely new to ScriptRunner. I could be wrong but this script doesn't handle when issues are still in the previous sprint but not done correct? I am trying to figure out how to find any issues in the current sprint that aren't closed, then close the sprint, start the next sprint, and move those found issues to the new sprint. Is there a better order and/or way to do this? 

3 votes
Siavash Mehrabi March 10, 2019

There is a feature request directly related to this question that you can vote for it:

https://jira.atlassian.com/browse/JSWSERVER-11569

I think this really needs to be a built-in feature for Jira.

0 votes
Jussi Niutanen January 28, 2022

Hi,

I have a crontab in Azure server and Python script to stop and start sprints automatically https://github.com/JussiNiutanen/JiraPython

I hope this helps. 

Best,

Jussi

Suggest an answer

Log in or Sign up to answer