jira api with ruby
My company follows a monthly release schedule that involves rounding up all the JIRA tickets that have been completed the last three and half weeks and ensuring they are ready for release. This is a somewhat tedious and a small but time-consuming part of it involves proofreading release notes (which is a custom field defined in JIRA) so they can be published to our website. As you can imagine I wasn’t about to do this manually every month. So I decided to automate this process.
The JIRA REST API
Atlassian offers a REST API in JIRA 5.0 or later. This API exposes a decent amount of resources and there are tutorials and extensive documentation available. There is even a REST API Browser that makes it really simple to investigate the API.
You can find the JIRA API here: http://yourjiraurl/rest/api/
Connecting with Ruby
The JIRA API is fully REST which means we can connect using almost any client capable of sending GET/POST requests. To do this with Ruby I chose curb Libcurl bindings for Ruby. This gem makes it really simple to do HTTP requests against the server and capture the response.
The JIRA API will return us a JSON object with our search results. To parse this I used the built-in JSON module. It will take the nasty mess of JSON and turn it into a nice object that you can work with.
I use this to get a list of tickets matching the latest release version according to our TeamCity release build. These items are run through a template using mustache. I then use an internal API to upload this automatically to our website. Done and done.
Example Code
I put some sample ruby code for connecting to the JIRA API on GitHub. You can find it here: https://github.com/minton/jira-api-example
- development
- ruby
- jira