Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of all JIRA issues (python)

I am trying to get a list of all JIRA issues so that I may iterate through them in the following manner:

from jira import JIRA

jira = JIRA(basic_auth=('username', 'password'), options={'server':'https://MY_JIRA.atlassian.net'})

issue = jira.issue('ISSUE_KEY')
print(issue.fields.project.key) 
print(issue.fields.issuetype.name) 
print(issue.fields.reporter.displayName)
print(issue.fields.summary)
print(issue.fields.comment.comments)

The code above returns the desired fields (but only an issue at a time), however, I need to be able to pass a list of all issue keys into:

issue = jira.issue('ISSUE_KEY')

The idea is to write a for loop that would go through this list and print the indicated fields.

I have not been able to populate this list.

Can someone point me in the right direction please?

like image 889
Walter U. Avatar asked Oct 02 '17 15:10

Walter U.


People also ask

How do I get a list of issues in Jira?

From your project's sidebar, select Issues and filters. Select an issue filter, like All issues to view all issues in the project. Select an issue from the list to open it.


4 Answers

def get_all_issues(jira_client, project_name, fields):
    issues = []
    i = 0
    chunk_size = 100
    while True:
        chunk = jira_client.search_issues(f'project = {project_name}', startAt=i, maxResults=chunk_size, fields=fields)
        i += chunk_size
        issues += chunk.iterable
        if i >= chunk.total:
            break
    return issues
issues = get_all_issues(jira, 'JIR', ["id", "fixVersion"])
like image 141
Ivan Bryzzhin Avatar answered Oct 23 '22 20:10

Ivan Bryzzhin


options = {'server': 'YOUR SERVER NAME'}
jira = JIRA(options, basic_auth=('YOUR EMAIL', 'YOUR PASSWORD'))
size = 100
initial = 0
while True:
    start= initial*size
    issues = jira.search_issues('project=<NAME OR ID>',  start,size)
    if len(issues) == 0:
        break
    initial += 1
    for issue in issues:
        print 'ticket-no=',issue
        print 'IssueType=',issue.fields.issuetype.name
        print 'Status=',issue.fields.status.name
        print 'Summary=',issue.fields.summary
       

The first 3 arguments of jira.search_issues() are the jql query, starting index (0 based hence the need for multiplying on line 6) and the maximum number of results.

like image 44
Mani Abi Anand Avatar answered Oct 23 '22 20:10

Mani Abi Anand


You can execute a search instead of a single issue get.

Let's say your project key is PRO-KEY, to perform a search, you have to use this query:

https://MY_JIRA.atlassian.net/rest/api/2/search?jql=project=PRO-KEY

This will return the first 50 issues of the PRO-KEY and a number, in the field maxResults, of the total number of issues present.

Taken than number, you can perform others searches adding the to the previous query:

&startAt=50

With this new parameter you will be able to fetch the issues from 51 to 100 (or 50 to 99 if you consider the first issue 0).

The next query will be &startAt=100 and so on until you reach fetch all the issues in PRO-KEY.

If you wish to fetch more than 50 issues, add to the query:

&maxResults=200

like image 3
Roberto Russo Avatar answered Oct 23 '22 20:10

Roberto Russo


You can use the jira.search_issues() method to pass in a JQL query. It will return the list of issues matching the JQL:

issues_in_proj = jira.search_issues('project=PROJ')

This will give you a list of issues that you can iterate through

like image 3
ZeddZull Avatar answered Oct 23 '22 20:10

ZeddZull