Summary
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.
Solution
-
Create a Run Condition that locates appropriate step and checks its status.
-
Create a link to the previous run of the procedure.
Examples
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:
$[/javascript 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"; } } runCondition; ]
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 .= '¶meters1_name=jobToRestart'; $url .= '¶meters1_value=$[jobId]'; # Set the Link property print "URL is $url\n"; $ec->setProperty("/jobs/$[jobId]/report-urls/Restart This Job", $url);