如果有人遇到同样的问题,我会使用自己的Try/Catch函数,将错误打印为红色:
def retry(retries, block) {
while(retries > 0) {
retries--
try {
block(retries)
return
} catch(Exception exception) {
printf "######################################\n" +
"\u001B[31mFAILED!!! Retries left = " + retries + "\n" +
"ERROR:\n" + exception.toString() + "\n" +
"STACK TRACE:\n" + exception.getStackTrace() + "\u001B[0m\n" +
"######################################"
if(retries == 0) {
throw exception
}
}
}
}
它可以这样使用:
retry(3) { retriesLeft ->
printf "retries left: ${retriesLeft}"
}