Skip to main content
Version: Release 22.3

Task Failure Handler

Using the Handling failure property you can enable failure handling on any task in a phase. You can use this to execute a Jython script when the task fails its execution or to skip the task.

Task attachments

  • Skip task: If the task fails, it is automatically skipped.

  • Restart phase: If the task fails, phase will be restarted based on the latest version of the current phase and release will be automatically resumed.

  • Define additional action: This option enables you to write your own Jython script to be executed if the task is going to fail. You can also use a script to do a clean up, retry, or conditionally skip or fail a task.

Scripts

important

The code provided in this topic is sample code that is not officially supported by Digital.ai. If you have any questions, contact the Digital.ai Support team.

important

Modification of a task status, such as: skip task, retry task, or other outcomes, must be the last line of your script.

If you do not modify the task status in your script, the task will be in the failed state after the script has run.

The script will run until it finishes or until the timeout is reached. You can modify the duration of the timeout in conf/xl-release.conf by changing this property:

xl.timeouts.failureHandlerTimeout=60 seconds

If the handler script produces an error or a time out occurs, the task will be marked as failed.

While the failure handler script is running, you can manually abort the task by clicking image on the right of the task, and selecting Abort.

Script examples

The following are some examples of how you can use the failure handler feature.

Retry a task a number of times

If your release process contains a third party dependency that is error prone and the task must be retried before you can conclude if something is broken:

  • Create a release variable of type Number, named attempt, and set the default value to 0.
  • Set the operation to Define additional action.
  • Set the following script:
if (releaseVariables['attempt'] < 3):
releaseVariables['attempt'] = releaseVariables['attempt'] + 1
taskApi.retryTask(getCurrentTask().getId(), "Retrying task from failure handler.")
else:
taskApi.skipTask(getCurrentTask().getId(), "Skipped task from failure handler.")

Set a variable to be used on a precondition

Depending on the status of a tasks, you can execute the succeeding task or group of tasks by setting the value of a variable and using it in a precondition:

  • Create an executeTask variable of type Boolean with the default value set to True (click on checkbox).
  • Set the operation to Define additional action.
  • Set the following script:
releaseVariables['executeTask'] = False
  • Set the precondition on a task or task group: ${executeTask}.

Skip a phase in advance

You can skip a complete phase if an error occurred in previous phases:

  • Set the operation to Define additional action.
  • Set the following script:
phase = phaseApi.searchPhasesByTitle("next phase", getCurrentRelease().getId())[0]
for task in phase.tasks:
taskApi.skipTask(task.getId(), "Skipped from failure handler.")
taskApi.skipTask(getCurrentTask().getId(), "Skipped task from failure handler.")

Restart Phase

Using this failure handler option you can restart the latest version of the current phase.

important

This will automatically resume the release after the restart.

Disabling the feature

If you want to disable this feature for a specific type of task, add the following line to the conf/deployit-defaults.propertiesfile:

  xlrelease.GateTask.failureHandlerEnabled=false

This snippet sample disables Handling failures for the Gate Task.

To disable this feature for all task types, add the following line to conf/deployit-defaults.propertiesfile:

  xlrelease.Task.failureHandlerEnabled=false

This snippet sample disables Handling failures for all task types.