x
login Signup

Get all running jobs whose job name contains "Test" using Perl API

I need to get all running jobs whose job name contains "Test" using Perl API. Is it possible?

avatar image By AnudeepLalam 17 asked Mar 17 at 07:51 PM
more ▼
(comments are locked)
10|750 characters needed characters left

1 answer: sort voted first

The following code looks for all running jobs whose job name contains "Test" and prints out the job name. If you wish to print out something else or additional to just the job name, uncomment the first print line and run the code to see the entire XML response, from which you can select other attributes to print:

 use strict;
 use ElectricCommander;
 $|=1;
 my $ec = new ElectricCommander();
 
 my @filterList;
 push (@filterList, {propertyName => "status",
                         operator => "equals",
                         operand1 => "running"});
 push (@filterList, {propertyName => "jobName",
                         operator => "like",
                         operand1 => "%Test%"});
 
 my $runningTestJobs = $ec->findObjects('job',
      { filter => [
          { operator => 'and',
              filter => \@filterList,
          }
     ]}
   );
 
 # print "running test jobs = " . $runningTestJobs->findnodes_as_string("/") . "\n";
 
 print "List of running jobs whose names contain 'Test'\n";
 my @jobs = $runningTestJobs->findnodes('//job/jobName');
 foreach my $jobNode (@jobs) {
   my $jName = $jobNode->findvalue("../jobName",$jobNode);
   print "  $jName\n";
 }
avatar image By cdoucet 80 answered Mar 19 at 04:01 PM
more ▼
(comments are locked)
avatar image AnudeepLalam Mar 22 at 12:55 PM

Thanks a lot cdoucet for sharing the solution. This is exactly what I was looking.

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.