Sidehistorik
...
https://stedolan.github.io/jq/
Den kan hentes her til Linux 64 Bit
Workflow
My IssueType is called "Repeatable Task" and has a very small workflow:
...
Upon the Transition of Initiate (id 61), the Post Function:
- creates Creates a copy of the Issue as a subtask
- sets Sets the the issue back to Status "Frozen"
...
Kodeblok | ||||
---|---|---|---|---|
| ||||
#!/bin/bash rm /tmp/crontab > /dev/null 2>&1 cd /opt/jira-cron/ IFS=$(echo -en "\n\b") TODAY=`date +%Y-%m-%d.%H:%M:%S` TransitionScript="/opt/jira-cron/jiraTransitionIssue.sh" JIRAFilter="issuetype%20%3D%20%22Repeatable%20Task%22%20AND%20status%20in%20%28Frozen%29%20%20and%20%22Cron%20Scheduling%22%20IS%20NOT%20NULL&maxResults=999" JIRAUSER="" JIRAPASS="" #echo https://jira.server.dk/rest/api/2/search?jql=$JIRAFilter CURLOPT_HEADER=0 export CURLOPT_HEADER curl -D -k -u $JIRAUSER:$JIRAPASS -X GET -H "Content-Type: application/json" https://jira.server.dk/rest/api/2/search?jql=$JIRAFilter > /tmp/issuelist.json IssueTotal=`cat /tmp/issuelist.json | ./jq-linux64 '.total'` echo "$TODAY Total: $IssueTotal" >> /opt/jira-cron/jiraMakeCrontab.log Count=0 for IssueId in `cat /tmp/issuelist.json | ./jq-linux64 '.issues[] .id'` do Count=$(($Count + 1)) IssueId=`echo $IssueId | sed "s/\"//g"` curl -D -k -u $JIRAUSER:$JIRAPASS -X GET -H "Content-Type: application/json" https://jira.server.dk/rest/api/2/issue/$IssueId > /tmp/issue.json IssueKey=`cat /tmp/issue.json | ./jq-linux64 '.key'| sed "s/\"//g"` #IssueStatus=`cat /tmp/issue.json | ./jq-linux64 '.fields.status.name'i | sed "s/\"//g"` cat /tmp/issue.json | ./jq-linux64 '.fields.customfield_12821' | sed "s/\"//g" | sed "s/\\\r//g" | sed "s/\\\n/;/g" | sed "s/\\\t/ /g" > /tmp/cronfield.json for CronEntry in `cat /tmp/cronfield.json | tr ";" "\n"` do echo "$CronEntry $TransitionScript $IssueKey > /dev/null 2>&1" >> /tmp/crontab echo "$TODAY Added ($Count): $cronEntry $TransitionScript $IssueKey to /tmp/crontab" >> /opt/jira-cron/jiraMakeCrontab.log done echo "" >> /tmp/crontab done #Replace JIRA Users crontab crontab /tmp/crontab |
The final line, making the JIRA crontab, can be extended with an error handler.
After running the script; - the /var/spool/cron/crontabs/jira (on Ubuntu LTS) should look like this:
Kodeblok | ||
---|---|---|
| ||
#Crontabs for SUPPORT-513 * * 1 * * /opt/jira-cron/jiraTransitionIssue.sh SUPPORT-513 >> /opt/jira-cron/jiraTransitionIssue.log 2>&1 #Crontabs for HOMEPAGE-3846 0 5 2 * * /opt/jira-cron/jiraTransitionIssue.sh HOMEPAGE-3846 >> /opt/jira-cron/jiraTransitionIssue.log 2>&1 #Crontabs for HOMEPAGE-2933 0 0 1 * * /opt/jira-cron/jiraTransitionIssue.sh HOMEPAGE-2933 >> /opt/jira-cron/jiraTransitionIssue.log 2>&1 #Crontabs for PROJECTTOOLS-2467 0 5 5 * * /opt/jira-cron/jiraTransitionIssue.sh PROJECTTOOLS-2467 >> /opt/jira-cron/jiraTransitionIssue.log 2>&1 |
...
Make sure the "jira" user has executeable acess to this. The TRANSITIONJSON defines the Initiate Transition (id 61)
Kodeblok | ||||
---|---|---|---|---|
| ||||
#!/bin/bash IFS=$(echo -en "\n\b") TRANSITIONJSON='{"transition": {"id": "61"}}' JIRAUSER="" JIRAPASS="" CURLOPT_HEADER=0 export CURLOPT_HEADER cd /tmp IssueKey=$1 if [ $IssueKey != '' ] then curl -D header.txt -u $JIRAUSER:$JIRAPASS -X POST --data $TRANSITIONJSON -H "Content-Type: application/json" https://jira.server.dk/rest/api/2/issue/$IssueKey/transitions rm header.txt else echo "No IssueKey as parameter" fi |
...