Scriptrunner - Cannot Release and Edit Version in the same Script

Hi all,

I'm having a strange issue when I try to release a Version and edit that Version's release date in the same script (see code below). If I try to do one or the other the change takes place just fine, but if I try to do both, only the second change works.

I've tried using VersionManager.update(version) to no avail, I've tried pausing for 10 seconds between function calls, and I've even tried running the two updates concurrently; no dice.

import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat

def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("project")
def versionManager = ComponentAccessor.getVersionManager()

def version = versionManager.getVersion(project.getId(), "3.4")

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2017-07-10")

//these are the updates in question
versionManager.releaseVersion(version, true) //this update will not persist
versionManager.editVersionReleaseDate(version, date) //this update will persist

Any advice would be great, thanks,

Ben

1 answer

1 accepted

This widget could not be displayed.

Hi Ben,

Your best off using VersionService to do this. It will do the validation for you and tell you exactly why you can't release or update a version.

Your script should look like the following which will release version "3.4" and set the release date as 2017-07-10.

 

import com.atlassian.jira.bc.project.version.VersionService
import com.atlassian.jira.component.ComponentAccessor

import java.text.SimpleDateFormat

def versionService = ComponentAccessor.getComponent(VersionService)
def projectManager = ComponentAccessor.getProjectManager()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def project = projectManager.getProjectByCurrentKey("project")
def version = versionService.getVersionByProjectAndName(user, project, "3.4")

def releaseDate = new SimpleDateFormat("yyyy-MM-dd").parse("2017-07-10")

def result = versionService.validateReleaseVersion(user, version, releaseDate)

if (result.isValid()) {
    versionService.releaseVersion(result)
} else {
    log.error "Could not relase version '${version.name}' due to the following errors: $result.errorCollection.errors"
}

Hope this helps.

Thanks,
Adam

 

Thanks Adam, that worked perfectly for me!

-Ben

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

182 views 2 0
Join discussion

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