java-mall-app/Jenkinsfile
panjunjie cc672b7178 增加从节点部署文件同步逻辑
增加从节点部署文件同步逻辑
2025-12-12 20:59:17 +08:00

40 lines
1.4 KiB
Groovy
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent any
environment {
DEPLOY_DIR = '/data/nginx/www/fafamall/h5' // 主节点部署目录(保留原配置)
DIST_PATH = 'dist' // 编译产物目录(保留原配置)
SLAVE_IP = '172.16.0.10' // 从节点 IP与之前一致
SLAVE_DEPLOY_DIR = '/data/nginx/www/fafamall/h5' // 从节点目标目录(与主节点一致)
SSH_PORT = '2203' // 从节点 SSH 端口(固定配置)
SSH_KEY = '/root/.ssh/id_rsa' // 主节点免密私钥路径(固定配置)
}
stages {
stage('拉取代码并验证') {
steps {
checkout scm
sh """
[ -d "${DIST_PATH}" ] || { echo "错误:未找到 ${DIST_PATH} 文件夹"; exit 1; }
echo "${DIST_PATH} 验证通过"
"""
}
}
stage('主节点部署') {
steps {
sh """
mkdir -p ${DEPLOY_DIR}
rm -rf ${DEPLOY_DIR}/*
cp -r ${DIST_PATH}/* ${DEPLOY_DIR}/
echo "主节点部署完成:${DIST_PATH} → ${DEPLOY_DIR}"
"""
}
}
}
post {
success { echo "🎉 h5 项目 - 主节点部署+从节点同步+Nginx重启全部完成" }
failure { echo "❌ h5 项目 - 部署/同步流程失败,请排查问题后重试" }
}
}