KBEC-00360 - Using Context-Relative Shortcuts to Properties on Pipelines and related objects

Article ID:360033189751
2 minute readKnowledge base
On this page

Summary

Shortcuts in CloudBees CD (CloudBees Flow) provide convenient runtime access to a property without knowing the exact name of the object that owns the property. Starting with CloudBees CD (CloudBees Flow) versions 7.0.2 and 7.2, pipeline-specific shortcuts to property paths that provide convenient runtime access include:

  • myPipelineRuntime

  • myStageRuntime

  • myTaskRuntime

  • myGateRuntime

These shortcuts can be used to configure a stage or task to run conditionally. They can be also used in the evaluation condition of an automated gate rule. Here are some sample JavaScript expressions depicting usage of these shortcuts.

Check the outcome of a task in the current stage

$[/javascript myStageRuntime.tasks.task1.outcome == "success"]

Where:

"task1" is the name of the task for which you want the outcome.

Check the outcome of a task in a different stage

$[/javascript myPipelineRuntime.stages.dev.tasks.task1.outcome == "success"]

Where:

"dev" is the stage name.

"task1" is the name of the task for which you want the outcome.

Get the application deployment details from a previous task in the same stage

$[/javascript myStageRuntime.tasks.task1.subapplication]
$[/javascript myStageRuntime.tasks.task1.environmentName]

Where:

"task1" is the name of the task invoking the application process.

Activate a gate rule only if a previous gate rule was successful

$[/javascript myGateRuntime.tasks["run tests"].outcome ==" success"]

Where:

"run tests" is the name of the gate rule.

*Note the variation in syntax when a task name contains a space.

Get the status of a gate rule while in a stage task

$[/javascript myPipelineRuntime.stages.dev.gates.PRE.tasks.task1.outcome]
$[/javascript myPipelineRuntime.stages.dev.gates.POST.tasks.task1.outcome]

Where:

"dev" is the stage name.

"task1" is the name of the task for which you want the status.

"PRE" and "POST" are the gate types.

Access a property created on a job started by a task

$[/javascript myPipelineRuntime.stages.dev.tasks.task1.job.propertyName]

Where:

"dev" is the stage name.

"task1" is the name of the task invoking the procedure or process.

Access a property created on a workflow started by a task

$[/javascript myPipelineRuntime.stages.dev.tasks.task1.workflow.propertyName]

Where:

"dev" is the stage name.

"task1" is the name of the task that invokes the workflow.

Set an evidence property in a condition-based automated gate rule

$[/javascript
        setProperty("/myTaskRuntime/evidence", "test value")
        true;
]

The evidence property appears as a comment after the task has completed.

Set an evidence property in a procedure-based automated gate rule

ectool setProperty "/myTaskRuntime/evidence" --value "test value"

In a Stage, to wait for 1st Group task’s subpipeline to complete in 2nd task in the same group

Use the precondition:

$[/javascript myGroupTaskRuntime.tasks["1st group task name"].subFlowRuntime.completed ]

In a Stage, to wait for 1st Group task’s subpipeline 1st stage in 2nd task in the same group

Use the precondition:

$[/javascript myGroupTaskRuntime.tasks["1st group task name"].subFlowRuntime.stages["Stage 1"] .completed ]