Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get fields from a specific Jira issue

I'm trying to get all the fields and values from a specific issue my code:

authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id) 
print issue.fields()

Instead of returning the list of fields it returns:

<jira.resources.PropertyHolder object at 0x108431390>
like image 970
Kobi K Avatar asked Jun 03 '15 09:06

Kobi K


3 Answers

authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id) 

for field_name in issue.raw['fields']:
    print "Field:", field_name, "Value:", issue.raw['fields'][field_name]

Depends on field type, sometimes you get dictionary as a value and then you have to find the actual value you want.

like image 100
ThePavolC Avatar answered Oct 09 '22 02:10

ThePavolC


Found using:

print self.issue_object.raw

which returns the raw json dictionary which can be iterate and manipulate.

like image 31
Kobi K Avatar answered Oct 09 '22 04:10

Kobi K


You can use issue.raw['fields']['desired_field'], but this way is kind of indirectly accessing the field values, because what you get in return is not consistent. You get lists of strings, then just strings themselves, and then straight up values that don't have a key for you to access them with, so you'll have to iterate, count the location, and then parse to get value which is unreliable.

Best way is to use issue.fields.customfield_# This way you don't have to do any parsing through the .raw fields Almost everything has a customfield associated with it. You can pull just issues from REST API to find customfield #'s, or some of the fields that you get from using .raw will have a customfield id that should look like "customfield_11111" and that's what you'll use.

like image 21
E. Oregel Avatar answered Oct 09 '22 03:10

E. Oregel