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

1 vote

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,323 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot