diff --git a/.gitlab/ci/preflight.gitlab-ci.yml b/.gitlab/ci/preflight.gitlab-ci.yml
index de99c5c734b490cc90d7bac27753481b9faa8e3a..4d8ee13929f61b05559675aee4f2dfc1b8daa8e7 100644
--- a/.gitlab/ci/preflight.gitlab-ci.yml
+++ b/.gitlab/ci/preflight.gitlab-ci.yml
@@ -36,13 +36,18 @@ rails-production-server-boot-puma-example:
   extends:
     - .rails-production-server-boot
   script:
-    - cp config/puma.rb.example config/puma.rb
-    - sed --in-place "s:/home/git/gitlab:${PWD}:" config/puma.rb
-    - echo 'bind "tcp://127.0.0.1:3000"' >> config/puma.rb
-    - bundle exec puma --environment production --config config/puma.rb &
-    - sleep 50  # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114124#note_1309506358
-    - retry_times_sleep 10 5 "curl http://127.0.0.1:3000"
-    - kill $(jobs -p)
+    - |
+      function test_puma_config_example() {
+        cp config/puma.rb.example config/puma.rb
+        sed --in-place "s:/home/git/gitlab:${PWD}:" config/puma.rb
+        echo 'bind "tcp://127.0.0.1:3000"' >> config/puma.rb
+        bundle exec puma --environment production --config config/puma.rb &
+        sleep 50  # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114124#note_1309506358
+        retry_times_sleep 10 5 "curl http://127.0.0.1:3000"
+        kill $(jobs -p)
+      }
+
+      run_with_custom_exit_code test_puma_config_example
 
 # Test the puma configuration present in
 # https://gitlab.com/gitlab-org/build/CNG/-/raw/master/gitlab-webservice/configuration/puma.rb
@@ -50,14 +55,19 @@ rails-production-server-boot-puma-cng:
   extends:
     - .rails-production-server-boot
   script:
-    - define_trigger_branch_in_build_env
-    - echo "TRIGGER_BRANCH is defined as ${TRIGGER_BRANCH}"
-    - curl --silent "https://gitlab.com/gitlab-org/build/CNG/-/raw/${TRIGGER_BRANCH}/gitlab-webservice/configuration/puma.rb" > config/puma.rb
-    - sed --in-place "s:/srv/gitlab:${PWD}:" config/puma.rb
-    - bundle exec puma --environment production --config config/puma.rb &
-    - sleep 50  # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114124#note_1309506358
-    - retry_times_sleep 10 5 "curl http://127.0.0.1:8080"
-    - kill $(jobs -p)
+    - |
+      function test_puma_config_cng() {
+        define_trigger_branch_in_build_env
+        echo "TRIGGER_BRANCH is defined as ${TRIGGER_BRANCH}"
+        curl --silent "https://gitlab.com/gitlab-org/build/CNG/-/raw/${TRIGGER_BRANCH}/gitlab-webservice/configuration/puma.rb" > config/puma.rb
+        sed --in-place "s:/srv/gitlab:${PWD}:" config/puma.rb
+        bundle exec puma --environment production --config config/puma.rb &
+        sleep 50  # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114124#note_1309506358
+        retry_times_sleep 10 5 "curl http://127.0.0.1:8080"
+        kill $(jobs -p)
+      }
+
+      run_with_custom_exit_code test_puma_config_cng
 
 ruby_syntax:
   extends: