Jira search all issues in a project with status Done or Closed
Asked Answered
S

5

6

I am trying to list all isues in a project with status Done or Closed. When I run a JQL-query with advanced search I get: 3096 issues in the project. However when I run it with python I get around 50 issues.

#/usr/bin/python
import jira.client
from jira.client import JIRA

options = {'server': 'http://jira.confluence.no' }
jira = JIRA(options, batch_auth=('admin', 'admin'))
project = jira.projects()

for project in projects:
   issues = jira.search_issues('project=JA')

for issue in issues:
    if str(issue.fields.status) == 'Done' or str(issue.fields.status) == 'Closed':
        print issue 

I am only getting 50 or so issues even though there is more than 3000 issues with the status Done or Closed with a JQL query.

Is there maybe a limit?

Staw answered 12/6, 2016 at 8:48 Comment(3)
How many projects do you have? As you currently have it, issues will contain the issues for the last project (even if that has no issues match "project=JA"). Do you mean to embed the for issue loop inside the for project loop? In fact, why do you have the for project loop at all?Dispensation
I tried to embeded the for issue into the for project loop however, I was seeing the same issues over and over again. Do you have any suggestion on how I could do it?Staw
You don't need the for poject loop at all. You are already telling search_issues which project you are interested in.Dispensation
D
11

From the docs at https://pythonhosted.org/jira/:

search_issues(jql_str, startAt=0, maxResults=50, validate_query=True,
              fields=None, expand=None, json_result=None)

Note the maxResults argument. I think you need to specify maxResults=False. Alternatively, do it in a loop like:

    got = 50
    total = 0
    while got==50:
        issues = jira.search_issues('project=JA', startAt = total)
        ....
        got = len(issues)
        total += got
Dispensation answered 12/6, 2016 at 9:42 Comment(3)
I think you misunderstood my question. I was to list all the issues, but I am only getting 50 issues somehow with the Code in the post above.Staw
@user3580316: I understood perfectly. You need to either specify "give me lots of results", or loop round getting them in chunks.Dispensation
This is the correct answer. When the query could return a lot of issues you should use pagination. You can also use the maxResults keyword argument to control how many results are in each page.Melitamelitopol
A
4

The answer of Martin Bonner is ok, but I'm just posting an answer to add more clarification.

The search_issues method uses the JIRA REST API to run the JQL query, so you can also look at the JIRA REST API documentation to understand the startAt and maxResults parameters:

enter image description here

From this documentation, I assume that maxResults only accepts an int as value.

Apology answered 12/6, 2016 at 12:2 Comment(7)
How do I define unlimit results? Is this correct? issues = jira.search_issues('project=JA',maxResults=500000)Staw
By default the number of issues returned is limited to 1000. For JIRA Cloud, you cannot change this value: confluence.atlassian.com/jirakb/…Apology
If you run your own JIRA, you can take a look at this article about how to configure your JIRA to change the max number of results: confluence.atlassian.com/jirakb/…. Although you should be aware that the limit is intentional and aimed to avoid performance and memory problems. The recommended approach is to retrieve results in batches using the maxResults and startAt parameters.Apology
I managed to get more results than 50, by changing the StartAt and MaxResults but how can I sort them by the key? And how can I list all issues which was created in may for instance?Staw
Those are different questions. Just read some of the JQL documentation. To add ordering you use a clause like 'ORDER BY key DESC'. To only get the issues created at some point, you query on the 'created' field. For more info look here: confluence.atlassian.com/jirasoftwarecloud/… and here: confluence.atlassian.com/jira/…Apology
Thanks! Where do I add the ORDER BY key DESC Is it done in the: jira.search_issues('project=JA',ORDER BY key DESC)?Staw
In your jql query: project=JA ORDER BY key DESCApology
A
0

Try this:

projects = jira.projects()
for project in projects:
    issues = jira.search_issues('project=XXXX', maxResults=None)
Axes answered 27/7, 2018 at 14:26 Comment(0)
O
-1

use maxResults parameter, in your case maxResults=3000 should work

Outlook answered 13/4, 2017 at 2:50 Comment(0)
T
-1

Try to use: maxResults=0, I think it will return about 100 results.

Teague answered 12/7, 2022 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.