From 240667d74f685528d0e0efdbd2e4dc3710fb7836 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Tue, 21 Apr 2026 16:39:08 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E4=BF=AE=E6=AD=A3=20CI/CD=20Bash=20PIP?= =?UTF-8?q?ESTATUS=20=E9=87=8D=E7=BD=AE=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 將 tar_status 與 docker_status 的賦值合併到同一行,解決 local 指令會重置 PIPESTATUS 導致變數為空的問題。 2. 增加變數非空檢查,預防非預期的語法錯誤。 3. 加強錯誤輸出的 Debug 資訊。 --- .gitea/workflows/deploy-demo.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/deploy-demo.yaml b/.gitea/workflows/deploy-demo.yaml index 9bcf4af..1fd2ccd 100644 --- a/.gitea/workflows/deploy-demo.yaml +++ b/.gitea/workflows/deploy-demo.yaml @@ -48,15 +48,15 @@ jobs: tar --exclude='.git' --exclude='node_modules' --exclude='vendor' --exclude='storage' --exclude='bootstrap/cache' -cf - . \ | docker exec -i "$container" tar -xf - -C /var/www/html/ - local tar_status=${PIPESTATUS[0]} - local docker_status=${PIPESTATUS[1]} + # 必須在同一行賦值,否則 PIPESTATUS 會被上一個 local 指令重置 + local tar_status=${PIPESTATUS[0]} docker_status=${PIPESTATUS[1]} echo " Result: tar=$tar_status, docker=$docker_status" - if [ $tar_status -le 1 ] && [ $docker_status -eq 0 ]; then + if [ -n "$tar_status" ] && [ "$tar_status" -le 1 ] && [ "$docker_status" -eq 0 ]; then return 0 else - echo "!!! Error: Sync failed for $container" + echo "!!! Error: Sync failed for $container (tar=$tar_status, docker=$docker_status)" return 1 fi }