Conditional branching

Conditional branching is supported for runbooks that contain action steps. You can configure which step to run next based on conditions that are evaluated after the current action has finished running. You can create separate branches for handling different error scenarios and also for variations of successful action completion. This allows you to:

  • Select different steps to proceed with for variations of running the action successfully
  • Depending on the error handling procedures that are available for the action, perform one or more of the following:
    • Collect diagnostic data
    • Analyze the error
    • Clean up leftovers and revert the effect of the failed action
    • Run an alternative action to achieve the original goal

When you edit a runbook, each action step (except if it is the last step within the runbook) shows an indicator if conditional branching has been configured, and if yes, how many conditions are associated with it. Click Configure conditional branches within the action step to open the related configuration dialog.

The ordering of the conditions is important. At runtime, the conditions are evaluated in sequence from top to bottom.

If none of the conditions matches at runtime, then the runbook activity proceeds to the next step. For example, if the action is of type SSH and you have created conditions for "Script return code equals 0" and "Script return code does not equal 0", then there is still the additional case that the script cannot be invoked at all (so there is no script return code), and the overall action status is "Failed". To prevent from falling back to the next step, you can create a third condition to handle this particular case separately, or you can replace the condition "Script return code does not equal 0" with "Status does not equal Successful", which covers both cases.

If a runbook runs fully automated and has conditional branching configured for some steps, then the resulting runbook activity reports as successful even if one or multiple steps have failed. Only if the last step fails, or if another step fails that has no conditional branching configured, will the overall runbook activity also be marked as not successful. For more information about the available exit states of actions, see How is the success rate of an action calculated?

Conditional branches are primarily intended to take effect when running the runbook in fully automated mode. When running the same runbook manually, conditional branching is observed as follows:

  • If the automation action has not been run yet or if it is still running, the default is to proceed with the next step.
  • If the automation action has finished, the runbook flow proceeds to the appropriate step based on the result of the automation action. The label of the Next step button is updated to include the target step number, and the related tooltip provides additional information.

Skipped steps are marked with an info box to say the step was skipped due to conditional branching. This information is available while running a runbook manually and also when reviewing runbook activity details (after the runbook activity has finished).

There are sample runbooks that illustrate how you can use conditional branching.

Procedure

  1. Click Configure conditional branches to open the configuration dialog.

  2. Click Add conditional branch to add a new branch.

  3. Select the property you want to use for the new condition. You can choose between the following properties:

    • Status: To compare the resulting status of the action with one of the supported values. For more information, see How is the success rate of an action calculated?
    • Output: To create a condition based on the action's output.
    • Execution time: To compare how long the action took to finish with a fixed number of seconds.
    • HTTP status code (for HTTP actions only): To compare the actual HTTP status code with a fixed HTTP status code.
    • Script return code (for SSH actions only): To compare the actual script return code with a fixed return code.
  4. Select the operator you want to use for the new condition. The available options depend on the type of property that has been selected in the previous step.

  5. Select or set the expected value to compare with. The available options depend on the type of property that has been selected.

  6. Select which step to go to if the condition is satisfied.

  7. Repeat steps 2-6 to create as many conditions as required.

  8. Use the Up and Down arrows to reorder the conditions as required. Note that at runtime they are evaluated in sequence (from top to bottom).