diff --git a/scripts/ci/extends/template-build-linux.yml b/scripts/ci/extends/template-build-linux.yml
index 5b598d5edf85ca0209e39bd3f9c4d9070da29fb2..7adeeff5be22edea5a634014401615f36874e5f1 100644
--- a/scripts/ci/extends/template-build-linux.yml
+++ b/scripts/ci/extends/template-build-linux.yml
@@ -27,7 +27,7 @@
             ctest_labels="default"
             if [ "$BUILD_CTEST_LARGE" = true ] ; then ctest_labels="large|$ctest_labels"  ; fi
             ctest_exit=0
-            ctest -T Test --no-compress-output -L "$ctest_labels" || ctest_exit=$?
+            ctest -T Test --no-compress-output -L "$ctest_labels" --repeat until-pass:2 || ctest_exit=$?
             if [ $ctest_exit -ne 0 ]; then
               echo "ctests failed (showing the last ${NUM_CTEST_ERROR_LINES} lines):"
               xsltproc ${CI_PROJECT_DIR}/scripts/test/ctest-error-output.xsl Testing/*/Test.xml | tail -n ${NUM_CTEST_ERROR_LINES}
diff --git a/scripts/ci/extends/template-build-win.yml b/scripts/ci/extends/template-build-win.yml
index 14ae4b65777e78fdc80fa0e16ac66e8405b8af5f..1f6675ad78b9ced65eb8023101b60efb5d22e92b 100644
--- a/scripts/ci/extends/template-build-win.yml
+++ b/scripts/ci/extends/template-build-win.yml
@@ -26,7 +26,7 @@
     - |
       if($env:BUILD_CTEST -eq "true")
       {
-        ctest -T Test --no-compress-output -LE large
+        ctest -T Test --no-compress-output -LE large --repeat until-pass:2
         $ctest_exit=$?
         if(!$ctest_exit)
         {