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

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.

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
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 Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

147 views 1 10
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