I have defined method to try push if there is any error while pushing the string the code will execute 3 times if the push failed. so what I want is that it should throw an exception with push failed if it failed after 3rd push retry. how I can rewrite this code with try catch block.
def push(String string) {
echo "push method start............"
int count = 0;
def status = sh(returnStatus: true, script: "${string}")
while(count<=2 && status != 0) {
sh "sleep 10"
++count;
echo "push : $count"
def status1 = sh(returnStatus: true, script: "${string}")
if (status1 == 0) {
echo "push : $count is success"
break
}
}
echo "dockerPushAndRetry method ends............"
}
return this