Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get tag and sprint value from jira using python

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 Apr 06, 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! 

Thanks @Shaun S Appreciate your help

Shaun S Atlassian Team Apr 09, 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

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

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

Glad it was of help ;)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you