How to fetch release date of a version using groovy script

Hi,

My requirement is to fetch the release date of a version for an issue using groovy.

I am able to get version name (08.00.10D). Next, I tried couple of ways using "getFixVersionsFor" and "version.getReleaseDate()" method for fetching the release date, however, couldn't succeed.

Version-ReleaseDate.png

Please help.

Nishant

8 answers

1 accepted

1 vote
Accepted answer

So you have a custom field which holds a version (or a set of versions). Using issue.fixVersions will not work, because this returns the value of the system "Fix Versions" field, which you are not using - you have a custom field instead.

What you need to do is retrieve the value of the custom field and then call one of the methods on VersionManager to get the Version object. You can then call getReleaseDate() on that object. Which VersionManager method to call depends on what is stored as value of the custom field - there are appropriate methods for finding versions by id or by name.

Many thanks Petar. Your directions helped me in resolving the same.

Hi petrov, is there a way we can use script runner for jira to disbale release if all the issues in the version are not resolved (done/closed) ?

Post you whole groovy script so we can answer your question. Generally the method you are looking for is Version.getReleaseDate() but since you say this does not work for you, there may be something else wrong.

Please find below the script...The section "HELP NEEDED HERE" is where I have to return the release date of the corresponding patch version. 

//Variable Declarations:START
def issue //To hold issue key-id
def customPatch//To hold custom field name as "Patch Version"
def patchValue //To store corresponding patch version value for an issue
//Variable Declarations:END
issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("ABCD")
//Fetching patch version:START
customPatch = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12345)
//Fetching patch version:END
//Checking if patch version field is not null and fetching patch version value:START
if(customPatch != null) {
    patchValue = (String) issue.getCustomFieldValue(customPatch);
    }
//Checking if patch version field is not null and fetching patch version value:END


"HELP NEEDED HERE...NEED TO RETURN RELEASE DATE OF PATCH VERSION stored in "patchValue ""

What is wrong in this? It is returning "[]"

def date = new Date()
date = issue.fixVersions*.releaseDate

return date

Hi Petar,

Could you please help? I am stuck.

Thanks,

Nishant

 

Let me get this straight - you have a custom field which holds a version? And you are not using the Fix Version system field for that?

 

Version-ReleaseDate.png

 

In the above image, we are creating versions with a specific name and release date like we do it in standard way in JIRA. Next, issues in the projects are tagged to particular versions to track their release.

All, I need is to return the release date corresponding to the attached version for an issue to a custom field.

Please do let me know, if any more information is required.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Statuspage

194 years of downtime: looking back on incident data from 2018

Statuspage customers logged more than 194 years of collective incidents in 2018. That’s a whopping 87% increase from the  104 years logged in 2017 , and we aren’t even through December yet....

47 views 1 5
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