Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

rerun failed step #1466

sriniefi ·
Hi Robin,

I want rerun a step until it is successful or certain number of retries. We have a copy files step where some file needs to be copied to network share.
It may happen that some time network may be down for a moment, in this the copy step fails. so we want a way to rerun this step for certain no times/or till it is successful.

Thanks,
Srinivas
  • replies 8
  • views 5964
  • stars 0
robinshen ADMIN ·
Hi Srinivas,

You may achieve this with below script (might need to be tuned for syntax) by adding a script step

groovy:
import java.io.File;
import com.pmease.quickbuild.util.FileUtils;

def numTries = 0;
def filePatterns = "**/*.java";
def srcDir = new File("/path/to/src/dir");
def destDir = new File("/path/to/dest/dir");
while (numTries < 3) {
try {
FileUtils.copyFiles(srcDir, filePatterns, destDir, true);
return; // copy successful, break the loop
} catch (Exception e) {
}
numTries++;
sleep(5000);
}
throw new RuntimeException("Tries 3 times, but still failed to copy files.");
sriniefi ·
Thanks Robin.

This script works for simple copy. We want to extend this to checkout repository, publish reports steps etc, where we want retry if the step fails for a certain no of times.

Thanks,
Srinivas
robinshen ADMIN ·
Hi Srinivas,

For retrial of general steps, please file an improvement request at track.pmease.com.

Regards
Robin
sriniefi ·
drdt ·
It may be a convoluted approach, but can you try the following?

- define a Repeat Parameter in your step, comma separated value list = "1,2,3,4,5" (up to as many times as you want to retry)
-- don't actually reference the Repeat Parameter in your step - it is just a counter
- set the Execute Condition to a script which equates to 'If all previous sibling steps are failed' (I am sure Robin can tell you how to do that)
- put your step inside of a Sequential composition step
- set the success condition of the Sequential composition step to 'If any child step is successful'.

This will (I believe) cause your step to execute repeatedly until either it succeeds (in which case the composition step will report success), or you exceed the desired count (in which case it will report failure).
robinshen ADMIN ·
[quote="drdt"]It may be a convoluted approach, but can you try the following?

- define a Repeat Parameter in your step, comma separated value list = "1,2,3,4,5" (up to as many times as you want to retry)
-- don't actually reference the Repeat Parameter in your step - it is just a counter
- set the Execute Condition to a script which equates to 'If all previous sibling steps are failed' (I am sure Robin can tell you how to do that)
- put your step inside of a Sequential composition step
- set the success condition of the Sequential composition step to 'If any child step is successful'.

This will (I believe) cause your step to execute repeatedly until either it succeeds (in which case the composition step will report success), or you exceed the desired count (in which case it will report failure).[/quote]
I verified and this works! The script equivalent for "if all previous sibling steps are failed" is "!step.parent.anyChildSuccessful"
sriniefi ·
many thanks, I will give it a try.

Thanks,
Srinivas
sriniefi ·
This requires one composition(sequential) step for each such rerun step, we would like to have this implemented in step feature itself.

Thanks,
Srinivas