CloudBees CD/RO steps can have a success , warning , error , or skipped outcome. Sometimes it is useful to execute or skip subsequent steps based on the outcome of a previous step. Used with error handling behavior available at the step level, sophisticated flow control can be achieved easily.
This tutorial demonstrates how to see the outcome of a preceding step and use run conditions to execute steps based on that outcome.
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:
The Procedure Details page for the procedure, "Checking outcome of preceding step", contains 3 steps:
-
step 1—force an error
—This step forces an error by attempting to run on a resource that does not exist. This action was achieved by hard-coding the step named"step 1 – force an error"
to run on a resource called "this-does-not-exist
". -
step 2—execute if step 1 failed
—This step uses JavaScript to check the outcome of the first step and executes if the first step failed. You can view the JavaScript for the run condition by clicking on the step name to take you to the Edit Step page—see the Run Condition field in the Advanced section. This statement checks the result of "step 1" for an error. If there is an error, "step 2" will execute. -
step 3—execute if step 1 succeeded
—This step also uses embedded JavaScript to check the outcome of the first step and executes if the first step succeeded. This is a slight variation of "step 2". Instead of looking at "step 1" for an error, this step checks for success and executes only if "step 1" succeeds. You can view the JavaScript for the run condition by clicking on the step name to take you to the Edit Step page—see the Run Condition field in the Advanced section.
Click Run to run this sample procedure and see the resulting job status on the Job Details page.
Implementation
Use the following instructions if you would like to practice creating steps to check the outcome of a preceding step.
Any changes you make within this tutorial will not be saved when you upgrade CloudBees CD/RO and you cannot transfer any steps from this tutorial to your projects. These instruction are provided only to give you a clearer definition for how to recreate this process in your own projects. |
-
Click the Create Step link.
-
In the Choose Step Type dialog, choose Command step to go to the New Step page.
-
Enter a Name for your step.
-
In the Command(s) text box, you can use the information in the above section. "Copy and paste" the provided JavaScript, changing the step name (between the brackets) to the new step name you supplied.
-
Repeat this process to create 3 steps, clicking OK to save each step.
-
When your 3 new steps are displayed on the Procedure Details page, click Run to see your steps running on the Job Details page.
Related information
Step —create new or edit existing step —Help topic