KBEC-00101 - Selectively suppressing property expansion

Article ID:360032831512
1 minute readKnowledge base

Description

Property expansion by default is an all or nothing selection when you reference a property.
Properties are always expanded within the text of the commands of the shell.
If you want to set a property as the text of the property instead of the value of the property using:

ectool setProperty /myJob/noExpanded "$[stepName]"

Solution variable concatenation

In a shell

Use the syntax of the shell to defeat property expansion. For example, using a bash shell:

dollar="\$"
ectool setProperty /myJob/noExpanded "$dollar[stepName]"

In perl

Make this step an ec-perl step and in Perl, concatenate two strings

use ElectricCommander;
$ec = ElectricCommander->new();
$ec->setProperty("/myJob/noExpanded", "\$" . "[stepName]", {jobStepId => $ENV{COMMANDER_JOBSTEPID}});

Solution javascript character obfuscation

Property expansion only takes place when the syntax is contiguous. Adding escape characters defeats property expansion, so replace the first two characters with a JavaScript reference that is the equivalent:

ectool setProperty /myJob/noExpanded "$[/javascript '\x24'][stepName]"
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.