diff --git a/scripts/rspec_helpers.sh b/scripts/rspec_helpers.sh
index dca5cc51b2524f2d929add477a20acd06aa924ae..51a5ff1c04d559ad598f86ce56f5d18322775f86 100644
--- a/scripts/rspec_helpers.sh
+++ b/scripts/rspec_helpers.sh
@@ -209,8 +209,13 @@ function change_exit_code_if_applicable() {
   local found_infra_error=$previous_exit_status
   local new_exit_code=$previous_exit_status
 
-  change_exit_code_if_known_flaky_tests $previous_exit_status || found_known_flaky_test=$?
-  change_exit_code_if_known_infra_error $previous_exit_status || found_infra_error=$?
+  # We need to call the GitLab API for those functions.
+  if [[ -n "$TEST_FAILURES_PROJECT_TOKEN" ]]; then
+    change_exit_code_if_known_flaky_tests $previous_exit_status || found_known_flaky_test=$?
+    change_exit_code_if_known_infra_error $previous_exit_status || found_infra_error=$?
+  else
+    echoinfo "TEST_FAILURES_PROJECT_TOKEN is not set. We won't try to change the exit code."
+  fi
 
   # Update new_exit_code if either of the checks changed the values
   # Ensure infra error exit code takes precedence because we want to retry it if possible