Add release web artifact rsync fallback
This commit is contained in:
@@ -25,6 +25,9 @@ pipeline {
|
||||
string(name: 'RELEASE_ROOT', defaultValue: '/opt/genarrative/releases', description: '生产 release 根目录')
|
||||
string(name: 'CURRENT_LINK', defaultValue: '/opt/genarrative/current', description: '当前版本软链接')
|
||||
string(name: 'WEB_LINK', defaultValue: '/srv/genarrative/web', description: 'Nginx 静态站点软链接')
|
||||
booleanParam(name: 'SYNC_WEB_ARTIFACT_FROM_BUILD_HOST', defaultValue: true, description: 'release 目标本地缺少 Web 大包时,是否通过 rsync 从构建机内网拉取')
|
||||
string(name: 'WEB_ARTIFACT_SYNC_HOST', defaultValue: 'genarrative-build-internal', description: 'rsync 源 SSH Host,通常来自 release 服务器上 Jenkins 运行用户的 ~/.ssh/config')
|
||||
string(name: 'WEB_ARTIFACT_SYNC_SSH_CONFIG', defaultValue: '', description: '可选,rsync 使用的 ssh config 绝对路径;留空使用当前用户默认 ~/.ssh/config')
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -109,9 +112,36 @@ pipeline {
|
||||
set -euo pipefail
|
||||
|
||||
artifact_dir="${WEB_ARTIFACT_ROOT}/${BUILD_JOB_NAME}/${BUILD_NUMBER_TO_DEPLOY}/${BUILD_VERSION}"
|
||||
if [[ ! -f "${artifact_dir}/web.tar.gz" ]]; then
|
||||
sync_enabled="${SYNC_WEB_ARTIFACT_FROM_BUILD_HOST:-true}"
|
||||
sync_host="${WEB_ARTIFACT_SYNC_HOST:-genarrative-build-internal}"
|
||||
sync_ssh_config="${WEB_ARTIFACT_SYNC_SSH_CONFIG:-}"
|
||||
|
||||
if [[ "${DEPLOY_TARGET:-development}" == "release" && "${sync_enabled}" == "true" ]]; then
|
||||
if [[ -z "${sync_host}" ]]; then
|
||||
echo "[web-deploy] release 目标需要同步 Web 大包,但 WEB_ARTIFACT_SYNC_HOST 为空。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[web-deploy] release 目标本地缓存缺少 Web 大包,尝试从 ${sync_host} 同步: ${artifact_dir}"
|
||||
if ! command -v rsync >/dev/null 2>&1; then
|
||||
echo "[web-deploy] 当前 release agent 缺少 rsync,请先安装 rsync 或预先挂载 Web 产物目录。" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "${artifact_dir}"
|
||||
|
||||
rsync_args=(-av --progress)
|
||||
if [[ -n "${sync_ssh_config}" ]]; then
|
||||
rsync_args+=(-e "ssh -F ${sync_ssh_config}")
|
||||
fi
|
||||
|
||||
rsync "${rsync_args[@]}" "${sync_host}:${artifact_dir}/" "${artifact_dir}/"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -f "${artifact_dir}/web.tar.gz" ]]; then
|
||||
echo "[web-deploy] 未找到构建机本地 Web 大包: ${artifact_dir}/web.tar.gz" >&2
|
||||
echo "[web-deploy] development 目标要求 Web 构建与发布共享同一 Linux 构建/开发部署机;release 目标需要预先同步或挂载 ${WEB_ARTIFACT_ROOT}。" >&2
|
||||
echo "[web-deploy] development 目标要求 Web 构建与发布共享同一 Linux 构建/开发部署机;release 目标会默认通过 rsync 从 WEB_ARTIFACT_SYNC_HOST 拉取,也可预先同步或挂载 ${WEB_ARTIFACT_ROOT}。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user