Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create sprint on board with groovy script

metinbulak July 31, 2019

I want to create new sprint on board with groovy script.

create code is:

Sprint.SprintBuilder builder = Sprint.builder();

builder.name("new-Sprint");
builder.startDate(1);
builder.endDate(1);
builder.completeDate(1);

Sprint newSprint = builder.build();

sprintManager.createSprint(newSprint);

 

when I list all sprints with groovy code, I can see created sprint bu not seen on any board in jira.

how to achive this?

3 answers

1 vote
Karpov Ruslan June 19, 2020

@Ivo_de_Vries  This is part of my code:

def newSprintId = this.createSprint(viewId, "${sprintKey}-${currentSprintID+1}", Sprint.State.FUTURE)

Sprint newSprint = sprintManager.getSprint(newSprintId as Long).getValue()

log.warn "Starting new sprint ${newSprint.name} with incomplete issues"

sprintIssueService.moveIssuesToSprint(user, newSprint, issues)
this.updateSprintState(suitableSprint, Sprint.State.CLOSED, null, null)
this.updateSprintState(newSprint, Sprint.State.ACTIVE, new DateTime().now(), new DateTime().now().plusWeeks(sprintTimes))

and methods for creating and updating sprints:

def createSprint(Long rapidViewId, String sprintName, Sprint.State state) {
def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)
Sprint.SprintBuilder builder = Sprint.builder().rapidViewId(rapidViewId).name(sprintName).state(state)

def newSprint = builder.build()
def outcome = sprintManager.createSprint(newSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${newSprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${newSprint.name} has been created."
return outcome.get().id
}
}

def updateSprintState(Sprint sprint, Sprint.State state, org.joda.time.DateTime startDate, org.joda.time.DateTime endDate) {
def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)

if(startDate && endDate && state == state.ACTIVE){
def currentSprint = sprint.builder(sprint).state(state).startDate(startDate).endDate(endDate).build()
def outcome = sprintManager.updateSprint(currentSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${sprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${sprint.name} has been activated."
}
}
else if(!startDate && !endDate && state == state.CLOSED){
def currentSprint = sprint.builder(sprint).state(state).build()
def outcome = sprintManager.updateSprint(currentSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${sprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${sprint.name} has been closed."
}
}
0 votes
Mario Schöck August 17, 2021

You also need to specify the board with:

builder.rapidViewId(boardId);

The board-ID is included in the board's URL after the parameter rapidView.

0 votes
Ivo_de_Vries March 30, 2020

@metinbulak were you able to solve this problem? I am able to close the current active sprints but now I want to automatically create a new sprint (as an increment of the previous one), move all tickets from the previous sprint to the newly created one and start it.

Karpov Ruslan June 19, 2020

This is part of my code:

def newSprintId = this.createSprint(viewId, "${sprintKey}-${currentSprintID+1}", Sprint.State.FUTURE)

Sprint newSprint = sprintManager.getSprint(newSprintId as Long).getValue()

log.warn "Starting new sprint ${newSprint.name} with incomplete issues"

sprintIssueService.moveIssuesToSprint(user, newSprint, issues)
this.updateSprintState(suitableSprint, Sprint.State.CLOSED, null, null)
this.updateSprintState(newSprint, Sprint.State.ACTIVE, new DateTime().now(), new DateTime().now().plusWeeks(sprintTimes))

and metods for creating and updating sprints:

def createSprint(Long rapidViewId, String sprintName, Sprint.State state) {
def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)
Sprint.SprintBuilder builder = Sprint.builder().rapidViewId(rapidViewId).name(sprintName).state(state)

def newSprint = builder.build()
def outcome = sprintManager.createSprint(newSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${newSprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${newSprint.name} has been created."
return outcome.get().id
}
}

def updateSprintState(Sprint sprint, Sprint.State state, org.joda.time.DateTime startDate, org.joda.time.DateTime endDate) {
def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)

if(startDate && endDate && state == state.ACTIVE){
def currentSprint = sprint.builder(sprint).state(state).startDate(startDate).endDate(endDate).build()
def outcome = sprintManager.updateSprint(currentSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${sprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${sprint.name} has been activated."
}
}
else if(!startDate && !endDate && state == state.CLOSED){
def currentSprint = sprint.builder(sprint).state(state).build()
def outcome = sprintManager.updateSprint(currentSprint)

if (outcome.isInvalid()) {
log.error "Could not update sprint with name ${sprint.name}, ${outcome.getErrors()}"
} else {
log.warn "${sprint.name} has been closed."
}
}
}

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events