From cf2998570ead800670a2c50e133125ac44c46f86 Mon Sep 17 00:00:00 2001
From: Jennifer Li <jli@gitlab.com>
Date: Wed, 12 Mar 2025 01:36:04 -0700
Subject: [PATCH] Run docs jobs with custom exit code

---
 .gitlab/ci/docs.gitlab-ci.yml | 30 ++++++++++++++++++++++--------
 scripts/utils.sh              |  4 +++-
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml
index 7cec66e240836..18cb4ba3d7fdd 100644
--- a/.gitlab/ci/docs.gitlab-ci.yml
+++ b/.gitlab/ci/docs.gitlab-ci.yml
@@ -47,10 +47,15 @@ docs-lint markdown:
   needs: []
   script:
     - source ./scripts/utils.sh
-    - yarn_install_script
-    - install_gitlab_gem
-    - scripts/lint-doc.sh
-    - scripts/lint/check_mermaid.mjs
+    - |
+      function docs_lint_markdown() {
+        yarn_install_script
+        install_gitlab_gem
+        scripts/lint-doc.sh
+        scripts/lint/check_mermaid.mjs
+      }
+
+      run_with_custom_exit_code docs_lint_markdown
 
 docs code_quality:
   extends:
@@ -97,8 +102,10 @@ docs-lint links:
     - .docs-markdown-lint-image
   stage: lint
   needs: []
+  before_script:
+    - source scripts/utils.sh
   script:
-    - lychee --offline --no-progress --include-fragments doc
+    - run_with_custom_exit_code lychee --offline --no-progress --include-fragments doc
 
 docs-lint deprecations-and-removals:
   variables:
@@ -111,8 +118,13 @@ docs-lint deprecations-and-removals:
   stage: lint
   needs: []
   script:
-    - bundle exec rake gitlab:docs:check_deprecations
-    - bundle exec rake gitlab:docs:check_windows
+    - |
+      function docs_lint_deprecations_and_removals() {
+        bundle exec rake gitlab:docs:check_deprecations
+        bundle exec rake gitlab:docs:check_windows
+      }
+
+      run_with_custom_exit_code docs_lint_deprecations_and_removals
 
 docs-lint redirects:
   image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}-alpine
@@ -121,5 +133,7 @@ docs-lint redirects:
     - .default-retry
     - .docs:rules:redirect-check
   needs: []
+  before_script:
+    - source scripts/utils.sh
   script:
-    - ./scripts/lint-docs-redirects.rb
+    - run_with_custom_exit_code ./scripts/lint-docs-redirects.rb
diff --git a/scripts/utils.sh b/scripts/utils.sh
index 6e1737195f1c4..60ab674941578 100644
--- a/scripts/utils.sh
+++ b/scripts/utils.sh
@@ -546,9 +546,11 @@ function run_with_custom_exit_code() {
   set +e # temporarily disable exit on error to prevent premature exit
 
   # runs command passed in as argument, save standard error and standard output
-  output=$("$@" 2>&1)
+  output=$(set -e; "$@" 2>&1)
   initial_exit_code=$?
 
+  echo "initial_exit_code: $initial_exit_code"
+
   local trace_file="stdout_stderr_log.out"
 
   echo "$output" | tee "$trace_file"
-- 
GitLab