Run Specific Steps only while in a Workflow

Article ID:360033191811
1 minute readKnowledge base

Description

A procedure must be able to run standalone, as well as being called from a state within a workflow. A single procedure is easier to maintain than two separate procedures, so a way needs to be available to not run certain steps when the procedure is not part of a workflow. This is done using the run condition on individual steps.

For example, you have a build procedure that is used for Continuous Integration (CI) builds, and the same procedure will be used for creating release builds. The CI builds are run through the CloudBees CD (CloudBees Flow) scheduler, thus running the procedure directly rather than within a workflow. Release builds are run in a workflow, and have additional steps that are needed to run that are not needed for the CI builds. Having one procedure to perform both builds is preferable to having two separate procedures.

Solution

Using the run condition, the flow of the procedure (and specifically what steps are run under what conditions) can be controlled. By using a run condition as follows:

$[/javascript (typeof(myWorkflow.workflowName) != "undefined")]

Using this condition, the specific steps that are needed for a release only (such as copying the release to an archive server, or setting certain workflow properties to be used in later states in the workflow) can be run only when the procedure is run within the workflow. When the procedure is not run in a workflow, those steps where this condition is set will be skipped.