jenkins SSH登录服务器,按分支部署

This commit is contained in:
sophie committed 2026-04-25 11:16:13 +08:00
1 parent d710a88d04
commit 3f5b6292ba
7 files changed
+119 -38

No files matched your search

+9 -4
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_NAME="${1:?Environment is required}"
ENV_NAME="${1:-default}"
COMPOSE_FILE="${2:?Compose file path required}"
ENV_FILE="${3:?Env file path required}"
ENV_FILE="${3:-}"
if docker compose version >/dev/null 2>&1; then
DC_CMD=(docker compose)
@@ -14,11 +14,16 @@ else
exit 1
fi
declare -a compose_args=(-f "${COMPOSE_FILE}")
if [[ -n "${ENV_FILE}" && -f "${ENV_FILE}" ]]; then
compose_args+=(--env-file "${ENV_FILE}")
fi
max_attempts=20
sleep_seconds=3
for ((i=1; i<=max_attempts; i++)); do
status=$("${DC_CMD[@]}" -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" ps --status running --services | wc -l)
status=$("${DC_CMD[@]}" "${compose_args[@]}" ps --status running --services | wc -l)
if [[ "${status}" -ge 2 ]]; then
echo "Healthcheck passed for ${ENV_NAME} environment."
exit 0
@@ -29,5 +34,5 @@ for ((i=1; i<=max_attempts; i++)); do
done
echo "Healthcheck failed for ${ENV_NAME} environment."
"${DC_CMD[@]}" -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" ps
"${DC_CMD[@]}" "${compose_args[@]}" ps
exit 1