back home

JIRA events can execute external programs!

Ever wondered how to automate JIRA server and execute external scripts when events are triggered? Here’s a simple example that will tell you exactly that!

You didn’t know that’s possible? Sure it is with a help from Automat my little JIRA plugin.

Each JIRA issue operation triggers an internal event - when for example issue is updated, or created, or commented, there’s plenty of different event types. So why not to use that to enhancing your workflow?

I thought about that. The only thing you need to do is installing Automat then your can put scripts in your JIRA-home directory and they will be automatically run. No other configuration is required!

Put the script file for each event into JIRA-home/automat subdirectory, each file needs to follow a naming convention (which is described in the plugin itself) for example issueCreated.sh will be executed whenever issue is updated. When you open a configuration page for the plugin you’ll see a list of handled events with respective filenames.

But what if you don’t want to use Shell to create your hooks in? There’s simple. Here’s an example of a simple hook that I created in python! Here’s issueUpdated.sh (arguments are following: JIRA site URL, issue key, user that performed the action):

#!/usr/bin/env python

import sys

try:

import requests

except:

print “run sudo easy_install requests”

exit(1)

USERNAME = “admin”

PASSWORD = “admin”

def issueUpdatedAt(jiraUrl, issueKey):

# ignore other projects than TST

if (not issueKey.startswith(“TST”)):

return

issueUrl = “%s/rest/api/2/issue/%s” % (jiraUrl, issueKey)

issue = requests.get(issueUrl, auth=(USERNAME, PASSWORD)).json()

# dump issue details to a file

with open(“/tmp/test.txt”, “w+”) as f:

f.write(str(issue))

if __name__ == “__main__”:

issueUpdatedAt(sys.argv[1], sys.argv[2]) 

It will connect back to the JIRA to obtain more details about the issue being updated. You can easily use any JIRA REST endpoint so scripts can be really smart!

Hope you found this tutorial useful. If you have any questions fell free to contact me.

Go to the plugin page.