Pipe Jira bugtracker deadlines to calendar using ICS-file

This is how I import my deadlines for tickets from our Jira bugtracker to our Zarafa ical gateway (running on localhost only but since I’ve a real account I could easily install a crontab for this for my system user).

Notes:

– The script makes use of phyton as well
– The script makes use of the Jira rest api (needs to be enabled)
– The script makes use of the (free) JIRA Calendar Plugin (https://marketplace.atlassian.com/plugins/com.atlassian.jira.ext.calendar/versions#b20107)
– The script uses a hardcoded filter id 10100. The filter must be created by the Jira user before. In my case it’s simply a filter that returns all projects I’m assigned to.
– The calendar used (e.g. „Jira“) must be manually created by the Zarafa user before and will be overwritten everytime the script runs! (Do not use default calendar)
– Dunno how to check whether ICS file loaded fine so run it manually and check whether new items show up in the calendar 🙂

It can probably easy adapted to other ics servers as well. I run this all 15 minutes during working days making use of crontab.


#!/bin/bash
JIRAUSER="changeme"
JIRAPASS="changeme"
JIRAICS="$HOME/jira.tmp.ics"
JIRAURL="jira.example.com"
#secure folder with e.g. umask 077
JIRACOOKIE="$HOME/.cookies/jira.cookie"
ZARAFAUSER=="changeme@example.com"
ZARAFAPASS=="changeme"
#
#Do NOT use default "Calendar", ICS will OVERWRITE it!
#Create an OWN calendar for Jira entries ONLY!
#
ZARAFACALENDAR="Jira"
if [ -f "$JIRAICS" ]; then
rm "$JIRAICS"
fi
if [ ! -f "$JIRACOOKIE" ]; then
JIRATEST=`/usr/bin/curl -s -u "$JIRAUSER":"$JIRAPASS" --cookie-jar "$JIRACOOKIE" "https://$JIRAURL/rest/api/2/user?username=$JIRAUSER" -s | python -mjson.tool | grep -oP "(?<=\"name\": \")[^\"]+"`
else
JIRATEST=`/usr/bin/curl -s --cookie "$JIRACOOKIE" "https://$JIRAURL/rest/api/2/user?username=$JIRAUSER" -s | python -mjson.tool | grep -oP "(?<=\"name\": \")[^\"]+"`
fi
if [ "$JIRATEST" != "$JIRAUSER" ]; then
echo "Error getting Jira username $JIRAUSER"
rm "$JIRACOOKIE"
exit -1
fi
/usr/bin/curl -s --cookie "$JIRACOOKIE" --output "$JIRAICS" "https://$JIRAURL/plugins/servlet/calendar?searchRequestId=10100&dateFieldName=duedate&showVersions=true" || exit $?
if [ -f "$JIRAICS" ]; then
/usr/bin/curl -s -u "$ZARAFAUSER":"$ZARAFAPASS" -T "$JIRAICS" "http://localhost:8080/ical/$ZARAFAUSER/$ZARAFACALENDAR"
rm "$JIRAICS"
fi

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Comments are closed.