Conditional Execution

2 minute readAutomation

Process automation frequently contains actions to be executed only if certain conditions are met. Conditional execution can be applied directly to your procedures rather than having to maintain larger scripts to handle these actions. For example, you may need to control whether or not to build on different operating system types.

This tutorial shows you how to implement simple conditional execution in a step.

To view an example procedure for this tutorial , go to the automation platform UI > Projects > EC-Tutorials- <version> , and click the procedure name.

An explanation of what you see:

This procedure defines one parameter and then uses a run condition to check the parameter value to decide whether or not to execute a step.

  • The Procedure Details page for the Conditional execution procedure contains a step named step 1. (Clicking on this step takes you to the Edit Step page.)

  • The Action column displays the command to be executed.

  • The Parameters section displays a parameter with values. The parameter named " Execute step 1 " was created as a checkbox.

If checked, the parameter equates to "true". In the run condition for "step 1", the parameter is read using the following property reference notation: $[Execute step 1].

(Clicking on the Parameter Name takes you to the Edit Parameter page to make modifications you may need.)

Click Run (at the top of the page) to run this sample procedure, which then takes you to the Run Procedure page where you could cause step 1 to execute by selecting the Execute step 1 checkbox.

  • Click Run again to go to the Job Details page to see the job created by running this procedure.

Implementation

Review the following instructions if you would like to see how to reproduce a conditional execution step.

Any changes you make within this tutorial are not saved when you upgrade CloudBees CD/RO. These instructions are provided only for more detailed information so you can easily see how to create your own "conditional execution" solutions in your procedures.
  • Click the Create Parameter link to go to the New Parameter page.

  • Enter a new parameter name.

  • Click the Type down-arrow and select Checkbox.

  • Select Initially checked?

  • For Default Value, type " true ".

  • Select Required?

  • Click OK to save your parameter and return to the Procedure Details page.

  • Click the step name to go to the Edit Step page.

  • Change the Run Condition text to check the new parameter name you supplied above.

  • Click OK to return to the Procedure Details page.

  • Click Run to go to the Run Procedure page to see 2 parameters where you can now decide if both are required or not.

  • Click Run to go to the Job Details page.

  • If only 1 parameter was "checked" as required, you will see the "skipped" notation in the Status column.

More complex run conditions can be implemented using inline JavaScript. See the tutorial, "Checking outcome of preceding step" for a more complex run condition example.