fuzzyworld

tower / commit

fix(ci): refresh branch previews through the trigger API

4903aa488d244ee56ea7df39341fb061ddde4280 · Pavel Safronov · 2026-09-27 17:23:06 -0700 · parents 342ab851a436

fix(ci): refresh branch previews through the trigger API

A trigger: job cannot start a pipeline in its own project; GitLab rejected the
preview job as invalid_bridge_trigger. It now POSTs to the pipeline trigger API
with a pipeline trigger token kept in the masked CI/CD variable
PAGES_TRIGGER_TOKEN, starting a default-branch pipeline that rebuilds every
branch's preview.

Usage: 1.0K in / 436.5K out / 127.1M cached (session tally)
rtk:   906.2K saved, 15.2% over 2700 cmds (global/lifetime)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
 .gitlab-ci.yml | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 011dab1..2bf7875 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,10 +30,16 @@ pages:
 # A push to any other branch rebuilds the site from the default branch, which is what
 # builds that branch's preview at /<branch>/. Parallel deployments would do this
 # natively, but they are Premium-only and this project is on the Free plan.
+#
+# Through the trigger API, with a pipeline trigger token in PAGES_TRIGGER_TOKEN (a masked
+# CI/CD variable): a `trigger:` job cannot start a pipeline in its own project, and
+# GitLab refuses it as invalid_bridge_trigger.
 preview:
   stage: deploy
-  trigger:
-    project: PavelSafronov/tower
-    branch: main
+  script:
+    - >
+      curl --fail --silent --show-error --output /dev/null
+      --form "token=$PAGES_TRIGGER_TOKEN" --form "ref=$CI_DEFAULT_BRANCH"
+      "$CI_API_V4_URL/projects/$CI_PROJECT_ID/trigger/pipeline"
   rules:
     - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH