Reactive tasks

Reactive tasks are extensible automated tasks that listen for events from webhooks endpoints and then execute a Jython script on the Release server.

Create a reactive task

Once you have already defined an HTTP Endpoint for Webhooks, you can create a reactive task.

In Release there is a supplied reactive task type under Webhook > Webhook: Wait for Json event.

Reactive task wait for json event example

The input options for the Webhook: Wait for Json event task are:

Option Description
Endpoint Configured HTTP Endpoint for webhooks to listen on.
Condition The condition that must be satisfied to transition the task from in-progress to complete.
Received event Output property bound to a text variable that will store the JSON of the webhook event (optional).

Reactive task condition

The reactive task condition is a Jython script that works similar to the Task preconditions: If the script returns True, the task will complete. If the script returns False, the task will stay in progress. If there is an error with the script, the task will fail.

In the script, you can access the Release Jython API, and the following properties: event, headers, parameters. event is the parsed JSON body of the webhook event, while headers and parameters are the HTTP request headers and parameters. The event, headers, parameters data is also accessible using dot access, e.g. event.commits[0].author, but the regular dict access is still available.

Define a custom reactive task

You can define your own reactive task type by extending it in synthetic.xml. Reactive tasks are a sub-type of Custom script task. All rules concerning custom script tasks are valid for reactive tasks. To define a custom reactive task, you also need to define either a condition property (inline script) or a webhookScriptLocation property (condition script file location).

Example of a custom reactive task:

Custom reactive task example

<synthetic xmlns:xsi=""
       xsi:schemaLocation=" synthetic.xsd">

    <type type="webhook.CustomReactiveTask" extends="webhook.ReactiveTask">
        <property hidden="true" transient="true" name="webhookScriptLocation" default="my/custom/dir/" />
        <property category="input" name="ticketId" kind="string"/>
        <property category="input" name="ticketStatus" kind="string" default="COMPLETED"/>
        <property category="output" name="event" label="Received event" kind="string" description="Payload of the received event"/>

The script:

global ticketId, ticketStatus

if not ticketId:
    raise Exception("Ticket ID must be defined")

if not ticketStatus:
    raise Exception("Ticket status must be defined")

result = == ticketId and event.status == ticketStatus