JIRA - Time spent in column
Recently I’ve been working on a small script that gathers information about Jira issues.
We wanted to know the time that a given ticket spends in each column on our kanban board. This can be useful for many reasons: for instance, you can measure the time an issue spent in the Open
status to get a ballpark estimate of the average time a ticket is waiting to be assigned. Or you can measure the average time in In Progress
to get an idea of velocity in general. You can of course measure any custom status (column) as well.
There is a plugin called the Time in Status for Jira Cloud, which accomplished this purpose. However, if you just want something free, you can hand-roll your custom reporting script like this.
# Requirements
- Access to Jira so that you can generate an access token and query boards
- You need to generate a Jira API access token following the instructions here.
- You need to export it like so:
export JIRA_TOKEN=<your Jira token here>
- And your email:
export JIRA_USER=<your email here>
- You need to export it like so:
sqlite3
(> 3.25
, for theLAG
window function)python3
# Details
For simplicity, I’ve used a SQLite database with only one table.
Please forgive the denormalised schema, but I think it’s best to store everything in one table for this simple use case.
In schema.sql
:
You can run this migration with sqlite3
$ sqlite3 changelog.db
$ sqlite> .read schema.sql
Create a python file to define the functions for getting the required details:
You can get all issues on a given board with this function: