Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get tag and sprint value from jira using python

Himanshu_Pant April 3, 2018

Hi Guys,

Could you please help to get Tag and Sprint value for particular issue

import jira.client
from jira.client import JIRA

options = {'server': 'https://example.com', 'verify':False}
jira = JIRA(options, basic_auth=('user', 'password'))
issues_in_project = jira.search_issues('project=11372 AND SPRINT not in closedSprints() AND sprint not in futureSprints()')
for value in issues_in_project:
print value.key , value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels,value.fields.tag

 

 

While running the python script , I got error

 

DWD-9933 Loading and Validating Products username username 2018-04-02T23:27:07.000-0700 None 2018-04-06 [u'DW-Products']
Traceback (most recent call last):
File "jira_test.py", line 23, in <module>
print value.key , value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels,value.fields.tag
AttributeError: type object 'PropertyHolder' has no attribute 'tag'

 

 

 

 

Please have a look once and  help me to achieve this

 

Thanks,

 

 

1 answer

1 accepted

2 votes
Answer accepted
Shaun S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 6, 2018

Hi Himansu,

 

Boy this was a tough one.  The sprint data associated with an issue is stored in the custom field "Sprint".  By calling "value.fields.customfield_<id>" I was able to get that data, but it's a nasty string containing sprint data other than the sprint name:

[u'com.atlassian.greenhopper.service.sprint.Sprint@5d9e64fb[id=1,rapidViewId=1,state=ACTIVE,name=Sample Sprint 2,startDate=2017-06-04T05:32:50.263Z,endDate=2017-06-18T05:52:50.263Z,completeDate=<null>,sequence=1,goal=<null>]']

With a little regex magic I was able to filter out the unnecessary data and only return the name.  Here's the code I used to achieve this. You'll want to replace the text "customfield_10004" with the customfield<id> that corresponds to the "Rank" field in your environment.

issues_in_project = jira.search_issues('project=11372 AND SPRINT not in closedSprints() AND sprint not in futureSprints()')


for value in issues_in_project:
for value in issues_in_project:
print value.key , value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels
for sprint in value.fields.customfield_10004:
sprint_name = re.findall(r"name=[^,]*", str(value.fields.customfield_10004[0]))
print sprint_name

Hope that helps! 

Himanshu_Pant April 9, 2018

Thanks @Shaun S Appreciate your help

Shaun S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 9, 2018

Happy I could help! I also forgot to mention that you'll need to import the regex library for the call to work.

import re
VEERESH RAMESH KHANORKAR
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2019

I ended up with :

 

      activeSprint = re.findall(r"name=[^,]*", [str(sprint) for sprint in a.fields.customfield_10004][-1])[0].split("=")[1]

 

;)

Like Phong Nguyen likes this
Phong Nguyen
Contributor
January 3, 2020

Thank you guys so much. I have been wasting hours of my life to get to this brilliant solution.

VEERESH RAMESH KHANORKAR
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 4, 2020

Glad it was of help ;)

Suggest an answer

Log in or Sign up to answer