KBEC-00082 - Iterating through properites, using xPath, to find 'error' or 'warning' values

Article ID:360032831792
1 minute readKnowledge base

Description

This article discusses how to find parameters and their values for a parent job step.

Solution

Because parameters are stored as properties on the job, use the getProperties command to access them.

Code

Use the following code:

use ElectricCommander;
my $ec = ElectricCommander->new();

my $xpath = $ec->getProperties( { jobId => $[/myJob/jobId], jobStepId => $ENV{COMMANDER_JOBSTEPID} } );
my $props = $xpath->find('//property');

foreach my $prop ($props->get_nodelist) {
    my $name = $prop->findvalue('propertyName');
    my $value = $prop->findvalue('value');
    if ($value eq 'error' or $value eq 'warning') {
        print "name=$name, value=$value\n";
    }
}
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.