KBEC-00160 - Job lifecycle - rerunning failed steps

Article ID:360033193591
2 minute readKnowledge base


This article describes how to set and transition a state for a job, for example, resume a job where it failed last time.

For example, if a job has 10 steps, and steps 1 through 4 previously succeeded, then next time resume at step 5.


  1. Create a Run Condition that locates appropriate step and checks its status.

  2. Create a link to the previous run of the procedure.


A sample procedure is attached.

The sample contains a few dummy steps that use Run Condition defined in a property. For testing purposes, you can force one or more of these steps to fail by changing "exit 0;" to "exit 1;". Also there is an empty "jobToRestart" parameter to hold a job ID that will be re-run.

The procedure also has an "always run" step that creates a link called "Restart this job". If you click this link, the procedure will rerun itself, skipping the steps that succeeded or were already skipped in its previous run. If you click "Run again", the procedure will rerun all of the steps. The "Run Condition" will work in subprocedure steps as well.

One item that is not implemented here: If your procedure has parameters, they must be passed to the link.

Code for Run Condition:

    function fullStepName(jobStep) {
        var result = "";
        var parentStep = jobStep.getProperty("/myParent");

        if (typeof(parentStep.stepName) != 'undefined') {
            result += fullStepName(parentStep) + "/jobSteps/";

        result += jobStep.stepName;
        return (result);

    var runCondition = "1";

    if (myJob.jobToRestart) {
        var path = "/jobs/$[jobToRestart]/jobSteps/";
        path += fullStepName(myJobStep);
        path += "/outcome";
        var outcome = getProperty(path);
        if (outcome == "success" || outcome == "skipped") {
            runCondition = "0";


Code for creating a link:

use strict;
$| = 1;
use ElectricCommander;
my $ec = new ElectricCommander;

    # Build the URL for restarting the job
    my $url =   'runProcedure.php?';
    $url .=     'runNow=1';
    $url .=     '&procedureName=$[/myJob/procedureName]';
    $url .=     '&projectName=$[/myJob/projectName]';
    $url .=     '&numParameters=1';
    $url .=     '&parameters1_name=jobToRestart';
    $url .=     '&parameters1_value=$[jobId]';

    # Set the Link property
    print "URL is $url\n";
    $ec->setProperty("/jobs/$[jobId]/report-urls/Restart This Job", $url);