There is no built-in support for job step retries if, for example, a user wants to retry a certain step or subprocedure call until it succeeds. One method of addressing this is by implementing a general job step retry pattern.
This job step retry pattern is a generic reusable pattern that can be used to control step retries within an CloudBees CD (CloudBees Flow) procedure. The pattern will handle both general command steps as well as subprocedure calls and allows for the user to control the number of valid retries before generating an error on the whole procedure. Each job step retry mechanism needs to be implemented in its own subprocedure and requires at least the “Number of retries” parameter to be passed in.
The basic design of a retry procedure is outlined below, there are 4 steps:
- The arbitrary command step or subprocedure call that should be run for each iteration of the retry mechanism. The error handling of this step should be set to ignore errors.
- A step that checks the outcome of the preceding step. If the preceding step failed and there are remaining retries left, enable a retry by cloning this procedure into the same project and set a property on the current call to instruct the following two steps that the retry is needed.
- If the step must be retried, run the procedure cloned in step 2, pass in a decremented “Number of retries” parameter.
- If the step had to be retried, delete the procedure that was cloned in step 2 and then subsequently called in step 3.
To enable this job step retry pattern, a factory procedure must be installed on the CloudBees CD (CloudBees Flow) server. An export of this factory procedure is attached to this article and should be installable on any CloudBees CD (CloudBees Flow) server since 3.1.
To generate a job step retry enabled procedure, run this factory procedure, which allows you to specify its destination project and name. Then, it is up to the user to modify the first step of this generated procedure to allow for job step retries. Again, the only prerequisite on this step is that its error handling must be set to ignore any errors.