How To Retry an Intermittently Failing Step


Networking issues can stop your job from running but one can mitigate this issue by implementing a for loop to be able to retry the failing step until it succeeds with a non-zero exit code or reaches the end of the last loop.


For-Loop Example and Explanation

An example command can be found below:

- run: for i in $(seq 1 5); do docker-compose up -d && s=0 && break || s=$? && sleep 10; done; (exit $s)

The for loop will run five times but this could be changed to any number by changing the 5 within the $(seq 1 5) section of the command.

Replace the `docker-compose up -d` command with the command to are retrying.

The sleep 10 can be changed or removed if required.

It is not recommended to remove the exit $s as this will pass the exit 1 to stop the run on the failing step rather than trying to continue.

If you need any assistance setting the command raise a support ticket with our team and we will be happy to help.


Additional Resources:

Was this article helpful?
3 out of 3 found this helpful



Article is closed for comments.