How to get Version from issue?

Suresh September 13, 2011

Hi All,

How to get version from and also from version to release date.The fallowing code i am useing

But I am not getting please any body have on this

GenericValue issueGv = issue.getProject();

<font style="font-size: x-small;" size="2"></font>

List versions =

<font style="font-size: x-small;" size="2"></font>

versionManager<u style="text-decoration: underline;">.getVersions(issueGv)</u>;

3 answers

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2011
List&lt;Version&gt; versions = componentManager.getVersionManager().getVersions(issue.getProjectObject().getId())
versions.first().getReleaseDate()

Suresh September 13, 2011

I have used but i am getting

InvocationException and NullpointerException while getting versions

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2011

What language are you using? I'm just trying to give you a pointer to the correct APIs.. first() is not valid in java. Make sure you've checked for nulls etc and have initialised componentManager.

Suresh September 13, 2011

Java only.I am trying to get earliest date from the vesions.Suppose fix version is multiple choice filed

So need get earleist date in those version(I am useing calculated custome plug-in)and displaying the date

ok how to initialise the componentManager I am new to this JIRA API

ComponentManager componentManager = ComponentManager.getInstance();

i am ComponentManager componentManager = ComponentManager.getInstance();

is it ok? and How to get release date from version list in java?

Suresh September 13, 2011

suppose i have added version v1.1 and v1.2

v1.1 release date is 2/7/2010

v1.2 release date is 2/7/2011

So i need to get v1.2 release date(2/7/2011) from the issue

This date i need show in the edit issue like filed "Sloution Available Date"

everytime the ticket is edited based on the earliest date of the field "fix version".

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2011

Yes your component manager line is correct. Fix version(s) is a multiplie choice field, so I'm assuming you're using fixversions as opposed to a custom field. Then you want the java moral equivalent of:

Date lowestRelDate = issue.getFixVersions().min {Version version -&gt; version.releaseDate}?.releaseDate

That is, get all the fix versions from the issue. Find the Version with the lowest release date, and get its release date. I can't write that in java for you, too boring. Maybe someone else will.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2011

I get it already. Without writing it for you I don't see what else I can say.

Suresh September 13, 2011

ThankYou so much I am getting release date from version.

And in getValueFromIssue methos it is return the release date Then How to set this date as custome filed

while edting the issue.

J Thomas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2011

Oh you mean this question https://answers.atlassian.com/questions/10303/how-to-get-date-from-fixed-version-and-copy-to-specific-attribute?

If it's a computed field then it does it for you when the issue is updated. To set the value on existing issues, re-index.

0 votes
Trevarthenson Virgil October 24, 2022

Fix version is the release version used to track different software developments and/or any updates. You fill out the Fix version to ensure that as you develop stories, and you can group them together when setting up a release delivery.

In any Software, you can view your issues according to which version they belong to. You can also drag-and-drop issues into a version to assign them to it, which you should do before you start work on the issues. This helps you plan your upcoming versions, which may span multiple sprints.

0 votes
Doreen Yen January 19, 2012

Jira 4.3, Python 2.7 environment.

Fetching the version (in which fixed) from an issue: use REST API.

import json
from restkit import Resource, BasicAuth, request

#... authentication

# Convert the text in the reply into a Python dictionary
issue = json.loads(response.body_string())


#...

fields = issue['fields']
for field_name in fields:
field_object = fields[field_name]

#...

elif field_name in ["fixVersions"]:
fDict = getValueDict(field_object['value'])
try:
for fkey,fval in fDict.items():
if fkey in ["name"]:
iDict['targetSW'] = fval
except:
iDict['targetSW'] = 'unset'

Setting the version (in which found) when creating an issue: REST is not available until Jira 5.0, must use suds.

Using the Python suds jira-cli-4.4, thanks to Matt Doar, modified it, to be able to set the Affects Version/s, by version name NOT id, so the flag used is -r "Affects Version/s:99.9.1" for version named '99.9.1'

Retrieves the version names for the project using getVersions.

Gets the id for the version name. Uses the existing API to set the version for creating the issue.

# Get the project versions
try:
jira_env['versionnames'] = soap.service.getVersions(auth, options.project)
except Exception, e:
jira_env['versionnames'] = [{'id':-1, 'name':'unavailable'}]
verf_choices = getChoicesStr(jira_env['versionnames'])

# Translate affectsVersions names to id
affectsVersions = []
if options.affectsversions:
nameV, valV = options.affectsversions.split(':')
avId = 'unknown'
for i,v in enumerate(jira_env['versionnames']):
if v['name'] == valV:
avId = v['id']

if avId == "unknown":
logger.error("Field version '%s' not found in %s" % (valV, verf_choices))
return 0
else:

version = {'id': avId.strip()}
affectsVersions.append(version)

You could code for fixVersions in the same way to be able to specify the name instead of the id.

MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 19, 2012

Glad you found the Python CLI useful!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events