5

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?

GlennV
  • 3,157
  • 4
  • 21
  • 36
  • 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? – Martin Bonner supports Monica Jun 12 '16 at 09:36
  • 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? –  Jun 12 '16 at 09:41
  • You don't need the `for poject` loop at all. You are already telling `search_issues` which project you are interested in. – Martin Bonner supports Monica Jun 12 '16 at 09:43

4 Answers4

8

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
  • 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. –  Jun 12 '16 at 09:45
  • 6
    @user3580316: I understood perfectly. You need to either specify "give me lots of results", or loop round getting them in chunks. – Martin Bonner supports Monica Jun 12 '16 at 15:01
  • 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. – Snorfalorpagus May 18 '18 at 09:47
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.

GlennV
  • 3,157
  • 4
  • 21
  • 36
  • How do I define unlimit results? Is this correct? `issues = jira.search_issues('project=JA',maxResults=500000)` –  Jun 12 '16 at 13:14
  • By default the number of issues returned is limited to 1000. For JIRA Cloud, you cannot change this value: https://confluence.atlassian.com/jirakb/changing-maxresults-parameter-for-jira-rest-api-779160706.html – GlennV Jun 12 '16 at 15:23
  • 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: https://confluence.atlassian.com/jirakb/how-to-increase-the-jira-search-results-limit-on-the-issue-navigator-357696242.html. 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. – GlennV Jun 12 '16 at 15:24
  • 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? –  Jun 12 '16 at 15:46
  • 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: https://confluence.atlassian.com/jirasoftwarecloud/advanced-searching-fields-reference-764478339.html#Advancedsearching-fieldsreference-CreatedCreatedDatecreatedDateCreated and here: https://confluence.atlassian.com/jira/advanced-searching-179442050.html#AdvancedSearching-ORDER_BY – GlennV Jun 12 '16 at 15:48
  • Thanks! Where do I add the `ORDER BY key DESC` Is it done in the: `jira.search_issues('project=JA',ORDER BY key DESC)`? –  Jun 12 '16 at 16:31
  • In your jql query: project=JA ORDER BY key DESC – GlennV Jun 12 '16 at 19:36
0

Try this:

projects = jira.projects()
for project in projects:
    issues = jira.search_issues('project=XXXX', maxResults=None)
joshuamabina
  • 1,210
  • 17
  • 25
-2

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