Skip to content

Commit

Permalink
Enable retry of ibmcloud login command to avoid timeout failure (#1357)
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab authored Aug 20, 2023
1 parent 620c497 commit 487032d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cd "${REPO_ROOT}" || exit 1
GOPATH_BIN="$(go env GOPATH)/bin/"
export PATH="${GOPATH_BIN}:${PATH}"
RESOURCE_TYPE="${RESOURCE_TYPE:-"powervs-service"}"
NO_OF_RETRY=${NO_OF_RETRY:-"3"}

# shellcheck source=../hack/ensure-go.sh
source "${REPO_ROOT}/hack/ensure-go.sh"
Expand Down Expand Up @@ -52,6 +53,23 @@ cleanup(){
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" || true
}

retry() {
cmd=$1
for i in $(seq 1 "$NO_OF_RETRY"); do
echo "Attempt: $i/$NO_OF_RETRY"
ret_code=0
$cmd || ret_code=$?
if [ $ret_code = 0 ]; then
break
elif [ "$i" == "$NO_OF_RETRY" ]; then
echo "All retry attempts failed!"
exit $ret_code
else
sleep 1
fi
done
}

install_ibmcloud_cli(){
if [ ${OS} == "Linux" ]; then
platform="linux_${ARCH}"
Expand All @@ -70,7 +88,7 @@ create_powervs_network_instance(){

ibmcloud config --check-version=false
# Login to IBM Cloud using the API Key
ibmcloud login -a cloud.ibm.com -r ${REGION}
retry "ibmcloud login -a cloud.ibm.com -r ${REGION}"

# Install power-iaas command-line plug-in and target the required service instance
ibmcloud plugin install power-iaas -f
Expand Down

0 comments on commit 487032d

Please sign in to comment.