IBM Cloud Docs
retry() function

retry() function

The retry() function is designed to perform a given command with a specified number of retry attempts and a delay between each attempts.

Parameters:

  • max_attempts : Maximum no of attempts to execute the command.
  • delay: The delay between each attempts.
  • command: The command to be executed.

Function Implementation:

  • Set local variables: max_attempts delay attempt_number exit_code
  • Execution of command
  • Retry loop : loop that continues until it succeeds or run till the max_attempt.
# <max_attempts>: Maximum no of attempts to execute the command.
# <delay>: The delay between each attempts.
# <command>: The command to be executed.
retry <max_attempts> <delay>  # executes the given <command to execute>
retry <max_attempts> <delay> <command to execute>

Return value:

  • If command succeeds in the attempts provided then retry Function returns with status ‘0’.
  • If it fails after all attempts , function returns with exit code.

Example:

source "${ONE_PIPELINE_PATH}"/tools/retry

# set value provided as argument
<max_attempts> = 5
<delay> = 10

retry 5 10 ibmcloud_region_set "$REGISTRY_REGION"