python-jira unable to return JIRA object key

Viewed 783

I am working on a tool for Jira using the python-jira library.

def find_ticket_key_by_name(search_string):
    global jira
    result = jira.search_issues('project=FSA and status != Done  and summary ~ "HOST TESTER-APP:SERVICE1-SERVICECOUNT" order by createdDate', maxResults=1)
    return result

The function above successfully returns a jira object

[<JIRA Issue: key=u'FSA-11', id=u'119060'>]

however if I attempt to print the key value

result.key

I get this error

AttributeError: 'ResultList' object has no attribute 'key'
3 Answers

What you are getting is a List in python, so try the following:-

  • result[0].key to get the key value
  • result[0].id to get id value.

You can always check type any data using type keyword, in your case it will be class 'jira.client.ResultList' which is a List object

If you want to get the key of issue you searched,

if result:
  for issue in result:
    print(issue.key)

It should help.

Related