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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

619 views 6 12
Read article

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