Auto creating JIRA issues

One of the ideas I always thought would be a good way to keep on top of technical debt and ensure that fixing bugs in Production was easy was to automatically create a JIRA ticket every time that an application throws an error.

(Background: Previously we had hooked up ElastAlert to our Slack channel to send a message whenever an application threw an error, however, this was considered “too noisy” by the client)

Now, people immediately balk at this idea, generally for two main reasons (though there are probably more):

  • The risk that a single bug could trigger many times (so JIRA ends up with lots of duplicates)
  • The fact that the application throws errors that aren’t bugs (are not actionable)

The first of these is very much a valid concern and the code should have some way of checking whether the error/log message is already in the system and if so, either do nothing or add a comment and/or attach extra information (stack traces, logs, memory dumps etc…) to the existing issue.

The second one is actually a feature of this system as it very quickly leads to better logging/error messages. My reasoning is that when you have the errors going to Slack/email/JIRA and they get directed to the developers, then very quickly you end up in a situation where the exception handling improves (in my opinion). The error log messages which “aren’t really errors” get downgraded to WARN, INFO or DEBUG and the actual message that is logged gets more specific (allows you to more quickly attribute it to a root cause) e.g. “Failed to start as can’t resolve database DNS” as opposed to just “Error on startup”.

So, in that spirit, I started having a play with the JIRA REST API. I used the documentation at these links:

Based on this, automatically creating JIRA’s with your credentials becomes as easy as running the following curl command:

curl -D- -u srdan:YOURPASSWORDHERE -X POST --data "@sample_issue.txt" -H "Content-Type: application/json"

With a sample issue file contents looking like:

  "fields": {
      "key": "PROJ"
    "summary": "REST ye merry gentlemen.",
    "description": "Creating of an issue using project keys and issue type names using the REST API",
    "customfield_12600": {"value": "4-Low"},
    "issuetype": {
      "name": "Bug"

Now, you might get an error back complaining about missing/invalid fields and so forth. Fortunately there’s a “meta” create API to tell you what fields are needed by which issue types. You can access this at:

curl -D- -u srdan:YOURPASSWORDHERE

This gets us started and lets us hook up the curl command to something like ElastAlert to create a JIRA for any errors. We still have work to do to use the “Search” API to de-duplicate issues at creation time, which I might cover in a separate blog post.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.