[FIX] 修正 CI/CD Bash PIPESTATUS 重置問題
1. 將 tar_status 與 docker_status 的賦值合併到同一行,解決 local 指令會重置 PIPESTATUS 導致變數為空的問題。 2. 增加變數非空檢查,預防非預期的語法錯誤。 3. 加強錯誤輸出的 Debug 資訊。
This commit is contained in:
parent
6eb9de4812
commit
240667d74f
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user