Automatically retry scripts to avoid network hiccups during CI process

- By Abhijit Kini on May 28, 2016

Sometimes intermittent network issues happen to the best of us, and it is particularly frustrating if it happens in the middle of a software install.

In this tutorial, I'll go over a quick way to mitigate the disruption of any installs that are part of your Continuous Integration builds.

Automatically retry scripts during Continuous Integration to avoid intermittent network issues

Before you begin

Ensure you have:

  • Have signed into Shippable using your GitHub or BitBucket credentials
  • Have an enabled project on Shippable platform, to run continuous integration

The shippable-retry functionality

In Bash, programs can pass a value to their parent process upon termination known as exit code. For all successful executions, the exit code value is zero and for failed executions, the value is non-zero.

Shippable has functionality called shippable_retry that can be included in the shippable.yml  file to mitigate the intermittent network issues that impact your CI build result. Using the shippable_retry will try the install command up to 3 times whenever it returns a non-zero exit code.

This functionality is available for all default installation commands such as npm install (node.js),  pip install (python),  bundler install (ruby), etc. It can also be used with custom installation from external sources such as  apt-get install (python), 

Examples of shippable.yml using

shippable-retry

Given below are few examples of using shippable_retry in the shippable.yml file:

build:
  ci:
    - shippable_retry sudo npm install
build:
  ci:
    - shippable_retry sudo apt-get update
build:
  ci:
    - shippable_retry pip install
post_ci: #Commit the container only if you want all the artifacts from the CI step - docker commit $SHIPPABLE_CONTAINER_NAME manishas/sample-node:tag - shippable_retry docker push manishas/sample-node:tag

Using the shippable_retry will help you mitigate the network hiccups that may occur while running your scripts. It is also a good idea to keep an eye on the status.shippable.com page to see if there is degraded performance due to network issues. 

Despite using this command, if you see failed builds and need help, please reach out by opening a support issue and we will troubleshoot the issue.


Try Shippable

Topics: continuous integration (CI), CI/CD, tutorial, tips, Bash, script