Skip to main content
Version: Release 23.1

Create Custom Trigger Types

You can use triggers to create and start new releases from within Release based on external events that you define. Release includes several defined trigger types that you can choose from the user interface. You can also define a new trigger type and associate it with a script to start releases based on other events.

Example scenario

The remainder of this topic describes a simple scenario in which you define a new trigger, create the associated script, attach it to a template, and use it to create a new release. As a similar example, the SVN Trigger plugin makes the commit ID available in this way.

Define the trigger in the type system

To define a new trigger type in Release's type system, add the definition to Release's type definition file in <XL_RELEASE_SERVER_HOME>/ext/synthetic.xml:

<type type="demo.MyFirstTrigger" extends="xlrelease.ReleaseTrigger" >
<!-- if you omit this property, Release will look for 'demo/MyFirstTrigger.py', based on the name of the type -->
<property name="scriptLocation" default="demo/find-events-to-trigger-release.py" hidden="true"/>
<!-- do not forget 'category="variables"' here! -->
<property name="triggerValueForUse" category="variables" required="false" />
</type>

For details on using scripts to automate tasks in Release, see API and scripting overview.

Create the trigger script

Create the script that will be executed each time the trigger executes. Based on the definition above, save the script as <XL_RELEASE_SERVER_HOME>/ext/demo/find-events-to-trigger-release.py:

import string
import random
import time

# an example of creating a value for use within your releases
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return''.join(random.choice(chars) for _ in range(size))

# this is the 'output' variable of the trigger from the type definition
triggerValueForUse = id_generator()

# the trigger will 'fire' when the value of this variable differs from the
# value that was set the last time the trigger was invoked
triggerState = triggerValueForUse

Restart the Release server to register the new trigger definition.

Attach the trigger to a template

Attach the trigger to a release template in a task that displays the value of &#123;&#123;triggerValueForUse&#125;&#125;, as set by the trigger.

  1. In the release template, select Variables from the left navigation bar.
  2. Define a template variable called ${valFromTrigger} and click Save.
  3. Select Triggers from the Show menu to go to the triggers page.
  4. Under Template variables, assign the ${triggerValueForUse} value (which will be set by the trigger) to the ${valFromTrigger} template variable.

Note: You can also use ${triggerValueForUse} in the Release Title field.

Trigger definition

  1. Save the changes.

Activate the trigger

To activate the trigger, create one release from the template, using the Release UI. The trigger will be running in the background (unless you disable it) and it will set the value of triggerState each time it is run.

When that value is different from the previous trigger invocation (which, in the case of this example, should be every time), a new release using the template will be created and started, with the ${valFromTrigger} template variable set to the value returned from the trigger.

In this simple example, the release will complete almost immediately, showing the value set by the trigger.

Note: Ensure that triggerState is set correctly inside your trigger script; it should be set to a different value from the previous execution exactly when you want the trigger to "fire" and create and start a new release.