KBEC-00010 - Running a job with a variable number of steps

Summary

This article describes how to run a job with a variable number of steps, to be determined as the job is running.

Use this approach whenever you have a list of items you want to iterate, but the contents and the length of the list are not known until runtime. For the purposes of display and error handling, you want each one to run as a separate step in ElectricCommander. For example, your build may have a number of sub-projects, and you want to query your SCM system to find out which sub-projects had checkins and build only those that changed. Every time you run this job, you will have a different list with a different number of projects in it.

Solution elements

  • The first step creates a new subprocedure and adds one step for each element in the list.
  • The second step calls the newly created subprocedure to run one step for each element in the list.
  • The third step deletes the created subprocedure to prevent procedure clutter.

Solution

Create the procedure using ectool commands

The list of items to iterate, in this example, is passed in a parameter as a comma-separated list. In a live application, the list can come from anywhere. Note that the procedure is given a name guaranteed to be unique so there will be no conflict, even if several jobs of this type are running simultaneously.

Command:

my $jobId = $[jobId];
my $projectName = '$[/myProject/projectName]';
my $resourceName = '$[/myResource/resourceName]';
my $procedureName = "VarStep_$jobId";
`ectool createProcedure "$projectName" "$procedureName" --resourceName "$resourceName"`;
`ectool setProperty /myJob/VarStepProcedureName "$procedureName"`;
my @names = split (",","$[commaSeparatedList]");
foreach  $name (@names) {
        my $command = "echo Hello, $name";
        my $stepName = "Step for $name";
        `ectool createStep "$projectName" "$procedureName" "$stepName" --command "$command"`;
}

Shell:

ec-perl

Run the created procedure as a subprocedure

Calling a nested procedure is very simple in ElectricCommander. Unfortunately, the procedure has a name not known until the job is already running. ElectricCommander handles this situation by referring to the nested procedure, by using a property reference. The procedure name is stored in a property during the first step, immediately after it creates the procedure.

We can, when creating the call to the subprocedure in the GUI, refer to that property as the subprocedure name.

Step type:

Run a nested procedure in this step

Subprocedure:

$[VarStepProcedureName]

Delete the created procedure

This step deletes the procedure that was created so the list of procedures will not be cluttered by these temporary procedures. Because the details of the jobsteps in the job itself shows which command was run, no important information is lost when the procedure is deleted,

Command:

my $procedureName = `ectool getProperty /myJob/VarStepProcedureName`;
chomp $procedureName;
my $projectName = '$[/myProject/projectName]';
print `ectool deleteProcedure "$projectName" "$procedureName"`;

Shell:

ec-perl

Applies to

  • Product Versions: all ElectricCommander versions
  • OS Versions: all supported OS versions
Have more questions? Submit a request

Comments

Powered by Zendesk