The below article will show you how to export all issues within your Jira instance to a single CSV file without any issue export limit. To use the below method, you need to generate an API token for your cloud environment and create a script using this python library called jiraone. You can install jiraone by using pip install jiraone or python3 -m pip install jiraone using a terminal.
See https://jiraone.readthedocs.io
As a Jira administrator, you might have been plagued with the request of transferring projects across multiple instances owned by your organization or probably due to a re-org you’re tasked with managing the shifting of multiple projects into a different instance to differentiate the various subsidiary within your organization. This task however daunting must be solved by the administrator and managed for effective project deployments. With the below API, you can simply perform this task, not only does it save you time, you can have all your project in a single file for storage in a CSV format. If you think about it, this is a great solution for creating a complete project backup of your Jira instance on a regular basis.
The purpose of this API solves multiple problems. Just to name a few, the first is uploading a single document to the External system importer rather than multiple documents due to the 1K limit. The second is that your external stakeholders can now have a single source of truth for analysing or auditing your Jira projects in other spreadsheet programs such as excel or numbers. The third is that you can have a backup of your entire project stored in your preferred storage service.
Now constructing a program that reads accurately each row within a CSV file wasn’t an easy task. Keeping track of each cell, when they change due to the swap of headers and sorting each column accordingly from both files was a challenge which I embarked on. That’s why you see before you a method that allows you to download all your projects into a single file using JQL without any issue export limitations. That’s right, you can export even 10K, 20K or more issues if you want.
To begin, you will need to create a configuration file in JSON following the below example and save it as a config.json file. This will be our source of authentication.
{
"user": "prince@example.com",
"password": "<APITOKEN_HERE>",
"url": "https://nexusfive.atlassian.net"
}
Then you can call this configuration using the below python script
from jiraone import LOGIN, issue_export
import json
file = "config.json"
config = json.load(open(file))
LOGIN(**config)
jql = "project in (AB, BC, IT, IP) order by created DESC"
issue_export(jql=jql)
The above is a minimal representation to trigger an export using this reporting API into a single CSV file. If the export is done on a single file, you can now simply import the issues into another Jira environment in one single shot rather than in multiple files of 1K issue export.
# If you want to rename the export filename,
# previous expression
export_file = "example_export.csv"
# Then, you can do
issue_export(jql=jql, final_file=export_file)
If you want to query each page and export only certain aspects of those pages, you need to know first the range of your Jira issues. i.e How many paginations are given to the total list of exported issues you want to export based on the JQL?
# previous expression
issue = PROJECT.issue_count(jql)
# result is a dictionary of issue count
# and max pagination of records pulled
# 1 page is equivalent to 1K records
count_issue = issue.count
# 18239
page_count = issue.max_page
# result
# 18
The above should give you an idea of what the max_page range is and how you can use it within the next example below.
# previous expression
issue_export(jql=jql, final_file=export_file,
page=(11, 18))
If you’re querying a Jira Datacenter or Jira Server, use the below
LOGIN.api = False
# previous statement
# change the API attribute to False when
# working with Jira DC or server prior to
# LOGIN instantiation.
issue_export(jql=jql, final_file=export_file,
page=(3, 6))
Now, let me explain the arguments that you can use within this method. These are the accepted keyword arguments that are used within the issue_export method. The folder argument expects a dir path in strings to a directory and allows you to specify which folder the dataset will be stored in. Please note that you do not necessarily need to have it set as it comes with a default directory. Usually, this should be a direct directory where you’re running the script. The jql argument requires a string following a valid JQL parameter. The final_file argument just basically allows you to name the final export filename. You do not necessarily need to have it set.
When you use the page argument, you can selectively pinpoint which export range you want. The page expects a tuple of integers and the index always starts from 0 and can extend up to the margin of your issue export range. If you want to know the page range and where it ends, you can call the PROJECT.issue_count(jql) method as shown above. Don’t worry, it validates everything, so it'll let you know what you did wrong.
The page arguments help to perform a sort of slicing of the file. Let’s say you downloaded the file at first and the file size is too large i.e. 100Mb or more and you want to break it down. Specifying where the page argument starts and end help in slicing the file into single chunks, so you can do multiples of 10K issues each for example.
The results from the terminal would be shown as well once the script starts to inform you of the progress.
Downloading issue export in CSV format.
<Response [200]> OK ::downloading issues at page: 3 of 6
<Response [200]> OK ::downloading issues at page: 4 of 6
<Response [200]> OK ::downloading issues at page: 5 of 6
<Response [200]> OK ::downloading issues at page: 6 of 6
Processing. Current progress: 25%
Processing. Current progress: 50%
Processing. Current progress: 75%
Processing. Current progress: 100%
Export Completed.File located at /Prince/EXPORT/test_example.csv
Please note as the files are merged into one, the size of the file will increase. I hope this helps to give you the ability to export your projects and migrate them across different instances of Jira and as well help you with having a backup of your entire project(s).
Prince Nyeche
51 comments