3

Is there a way to get the start and end date of a sprint in JIRA using the python JIRA library? I can get a jira.client.ResultList with all the sprints within the board of interest using jira.sprints(jira.boards()[<sequence number of the board of interest>].id). The list looks like this:

[<JIRA Sprint: name='LSD Sprint 1', id=1>,
...
<JIRA Sprint: name='LSD Sprint 14', id=14>]

Could I somehow access the start and end date for each sprint using something similar to issue.fields which returns me jira.resources.PropertyHolder, from which I can access additional data ?

altern
  • 5,829
  • 5
  • 44
  • 72
Mario Christov
  • 141
  • 1
  • 8
  • I know this is for Python, but within `bash`, you can get it using this script: https://stackoverflow.com/a/60378905/1499296 – AKS Feb 24 '20 at 18:46

3 Answers3

2

For testing I used jirashell (python-jira 1.0.10), JIRA 6.3.11, JIRA 7.2.3, JIRA AGILE REST API v1.0. I ran following code in jirashell:

dir(jira.sprints(jira.boards()[0].id)[0])

It prints all methods and attributes of the sprint object:

['AGILE_BASE_REST_PATH',
 'AGILE_BASE_URL',
 'AGILE_EXPERIMENTAL_REST_PATH',
 'GREENHOPPER_REST_PATH',
 'JIRA_BASE_URL',
 '_READABLE_IDS',
 '__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__format__',
 '__getattr__',
 '__getattribute__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_base_url',
 '_default_headers',
 '_get_url',
 '_load',
 '_options',
 '_parse_raw',
 '_resource',
 '_session',
 'delete',
 'find',
 'id',
 'linkedPagesCount',
 'name',
 'raw',
 'self',
 'sequence',
 'state',
 'update']

As you can see, the list does not contain startDate or endDate attributes. Nevertheless, quick googling for sprint startDate and endDate properties via JIRA REST API showed that API DOES support such properties. But it turned out that python-jira uses old version of JIRA AGILE REST API. For example, when I run jira.sprints(jira.boards()[0].id)[0].self, I get https://[JIRA_URL]/rest/greenhopper/1.0/sprint/[ID] as a result (not agile/1.0 as mentioned in the answer where API supports startDate and endDate properties). Also python-jira throws a message Old private GreenHopper API is used, all parameters will be ignored.

So, I assume it is not possible to get startDate and endDate using python-jira due to old version of the JIRA AGILE API that it uses.

altern
  • 5,829
  • 5
  • 44
  • 72
  • 1
    It's now possible to use the *agile* rest path as option: `jira = JIRA("https://myjira.com", auth=(user, password), options={"agile_rest_path": GreenHopperResource.AGILE_BASE_REST_PATH})` See `jira.resources.GreenHopperResource` for details. – Powerswitch Oct 26 '19 at 22:24
2

Use sprint_info(board_id, sprint_id)

This will return a dict of the sprint information. I wanted the date back as date formats, so I have some code that handles the conversion below and copes with the None values that are returned. Took ages to find this one, so thought a reply would be good as my first answer on Stack Overflow!!

    for board in boards:

        jira_sprints = jira.sprints(board.board_id)

        for jira_sprint in jira_sprints:

            sprint_info = jira.sprint_info(board.board_id, jira_sprint.id)

            board_id = board.board_id
            board_name = board.board_name
            name = sprint_info['name']
            id = sprint_info['id']


            if sprint_info['startDate'] != 'None':
                date_from = datetime.datetime.strptime(sprint_info['startDate'], "%d/%b/%y %I:%M %p").date()
            else:
                date_from = None
            if sprint_info['endDate'] != 'None':
                date_to = datetime.datetime.strptime(sprint_info['endDate'], "%d/%b/%y %I:%M %p").date()
            else:
                date_to = None
            state = sprint_info['state']
dan_g
  • 21
  • 1
1

Found a workaround for my issue, using the python requests library. Here is the link to it: http://docs.python-requests.org/en/master/

I used the following to get to the start and end date for the sprint of interest:

import requests
jiraResponse     = requests.get('https://<YOUR ATLASSIAN DOMAIN>.atlassian.net/rest/agile/1.0/board/<BOARD ID OF INTEREST>/sprint', auth=(<YOUR JIRA CREDENTIALS>))
jiraResponseJSON = jiraResponse.json()

jiraResponseJSON then is a dictionary whose values-key contains all the sprints contained in the board of interest within a list of objects, which themselves have the keys 'completeDate', 'endDate', and 'startDate'.

'endDate' is obviously available before the sprint is actually closed, whereas 'completeDate' becomes available only when the sprint gets closed, e.g. its status changes from active to closed.

Examples for what I used:

startDate = jiraResponseJSON['values'][<SPRINT NUMBER>]['startDate'][:10]
endDate   = jiraResponseJSON['values'][<SPRINT NUMBER>]['completeDate'][:10]

Having found the start and end date for a sprint, one could then further use both of them as variables in a python-jira query such as:

jira.search_issues('project=<YOUR PROJECT NAME> and issuetype=bug AND status changed to closed DURING ("' + startDate + '", "' + endDate + '")', maxResults=100)

Mario Christov
  • 141
  • 1
  • 8