Reactive tasks are extensible automated tasks that listen for events from webhooks endpoints and then execute a Jython script on the Release server.
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.
The input options for the Webhook: Wait for Json event task are:
|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).|
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 is the parsed JSON body of the webhook event, while
parameters are the HTTP request headers and parameters.
parameters data is also accessible using dot access, e.g.
event.commits.author, but the regular dict access is still available.
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:
<synthetic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.xebialabs.com/deployit/synthetic" xsi:schemaLocation="http://www.xebialabs.com/deployit/synthetic synthetic.xsd"> <type type="webhook.CustomReactiveTask" extends="webhook.ReactiveTask"> <property hidden="true" transient="true" name="webhookScriptLocation" default="my/custom/dir/CustomReactiveTaskScript.py" /> <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"/> </type> </synthetic>
global ticketId, ticketStatus if not ticketId: raise Exception("Ticket ID must be defined") if not ticketStatus: raise Exception("Ticket status must be defined") result = event.id == ticketId and event.status == ticketStatus