For a roundtrip integration into JIRA, the services called via the Call a Service postfunction must issue callbacks to JIRA when the the service finished. These callbacks should transition issues into a follow-up status in which they reflect the outcome of the service call.

To support those callbacks, the plugin adds several parameters to the service call. Some of those parameters are added automatically, some are only added if specified explicitly.

Callbacks may be implemented by using the core JIRA REST API or other tools like the JIRA CLI.

Automatically added parameters

To provide the service call with the necessary information for callbacks to JIRA, the following parameters are added automatically to each service call:

  1. jiraBaseUrl - contains the base URL of the JIRA instance that issued the service call
  2. issueKey - contains the key of the JIRA issue whose status change triggered the service call

Custom Parameters

Further the postfunction configuration screen allows entering values for transitions the callback should perform depending on the service outcome:

  1. successTransition - contains the ID of the transition to perform if the service call finished successfully
  2. failureTransition - contains the ID of the transition to perform if the service call finished unsuccessfully

Basic Example for Jenkins/Hudson:

This example shows how callbacks may be implemented using the JIRA CLI.

To implement a call back in Jenkins/Hudson add a final shell build-step to your job and enter the following code as command:

bash /tmp/callback-jira.sh -i ${issueKey} -j ${jiraBaseUrl} \
                           -l ${WORKSPACE}/../builds/${BUILD_NUMBER}/log \
                           -f "${failureTransition}" -s "${successTransition}"

Then create /tmp/callback-jira.sh with the content below and ensure that it is executable for the user which owns the Jenkins/Hudson process.

This is a very simple example which shows the basics - especially the log-parsing part may need a bit more coding to create better feedback.

#!/bin/bash
#
# callback-jira.sh - issue a callback to JIRA after running a Jenkins job
#
# customize these settings to your build and JIRA configuration:
#
SUCCESS_PATTERN="Finished: SUCCESS"
USER=admin
PASSWORD=xxx
#
# these are set via commandline:
#
ISSUE_KEY=""
JIRA_URL=""
LOG_FILE=""
SUCCESS_TRANSITION=""
FAILURE_TRANSITION=""
#
while getopts "i:j:l:f:s:" opt; do
    case $opt in
        i)  ISSUE_KEY=$OPTARG
            ;;
        j)  JIRA_URL=$OPTARG
            ;;
        l)  LOG_FILE=$OPTARG
            ;;
        s)  SUCCESS_TRANSITION=$OPTARG
            ;;
        f)  FAILURE_TRANSITION=$OPTARG
            ;;
    esac
done
#
# check
#
if [ -z "$ISSUE_KEY" ] ; then
    echo "Error - no issue key specified"
    exit 1
fi
if [ -z "$JIRA_URL" ] ; then
    echo "Error - no JIRA URL specified"
    exit 1
fi
if [ -z "$LOG_FILE" ] ; then
    echo "Error - no log file specified"
    exit 1
fi
if [ -z "$SUCCESS_TRANSITION" ] ; then
    echo "Error - no success transition specified"
    exit 1
fi
if [ -z "$FAILURE_TRANSITION" ] ; then
    echo "Error - no failure transition specified"
    exit 1
fi
#
#
#
result=$(egrep -a -e "${SUCCESS_PATTERN}" $LOG_FILE)
#
TRANSITION=$FAILURE_TRANSITION
if [ ! -z "$result" ]; then
        TRANSITION=$SUCCESS_TRANSITION
fi
URL=${JIRA_URL}/rest/api/latest/issue/${ISSUE_KEY}/transitions?transitionId=$TRANSITION
DATA="{\"fields\":{\"comment\":\"Executed job successfully\"} }"
#
echo curl -u <credentials> -X PUT $URL --data "$DATA"
set -x
curl -u ${USER}:${PASSWORD} -X PUT $URL --data "$DATA"