@@ -580,6 +580,55 @@ function dotest {
580580 fi
581581}
582582
583+ # Build one entry from the test list file. Retry 5 times on failure.
584+
585+ function retrytest {
586+ # Remember the Fail Status and clear it for each build
587+ local line=$1
588+ local prevfail=$fail
589+ local backoff=60 # Initial Exponential Backoff, in seconds
590+
591+ # Build and retry 5 times on failure, with Random Exponential Backoff
592+ local maxbuilds=6
593+ for (( i = 1 ; i <= $maxbuilds ; i++ )) ; do
594+ echo " Build Attempt $i "
595+ fail=0
596+ dotest $line
597+
598+ # Don't retry if the build succeeded
599+ if [ ${fail} -eq 0 ]; then
600+ break
601+ else
602+ # Build Failed: Clean up any corrupted downloads, don't reuse
603+ git -C $nuttx clean -fd
604+ git -C $APPSDIR clean -fd
605+ pushd $nuttx ; git status ; popd
606+ pushd $APPSDIR ; git status ; popd
607+ fi
608+
609+ # If Previous Build already failed: No point retrying
610+ if [ ${prevfail} -ne 0 ]; then
611+ break
612+ fi
613+
614+ # If this is Final Retry: Don't wait
615+ if [ $i -eq $maxbuilds ]; then
616+ break
617+ fi
618+
619+ # Wait for Random Exponential Backoff, then retry
620+ delay=$(( (RANDOM % $backoff ) + 1 ))
621+ echo " Wait $delay seconds ($backoff backoff)"
622+ backoff=$(( $backoff * 2 ))
623+ sleep $delay
624+ done
625+
626+ # Return the Previous Fail Status, unless this build failed
627+ if [ ${fail} -eq 0 ]; then
628+ fail=$prevfail
629+ fi
630+ }
631+
583632# Perform the build test for each entry in the test list file
584633
585634for line in $testlist ; do
@@ -588,10 +637,10 @@ for line in $testlist; do
588637 dir=` echo $line | cut -d' ,' -f1`
589638 list=` find boards$dir -name defconfig | cut -d' /' -f4,6`
590639 for i in ${list} ; do
591- dotest $i ${line/ " $dir " / }
640+ retrytest $i ${line/ " $dir " / }
592641 done
593642 else
594- dotest $line
643+ retrytest $line
595644 fi
596645done
597646
0 commit comments