java-mall-app/Jenkinsfile
2025-12-12 20:54:24 +08:00

51 lines
2.0 KiB
Groovy
Raw 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}"
# 2. Nginx 操作(优先热重载,无停机)
echo "检查 Nginx 配置语法..."
/usr/sbin/nginx -t # 先校验配置,避免重载失败
echo "热重载 Nginx 配置..."
# Debian systemd 下的正确写法(绝对路径+sudo需提前配置免密
sudo /usr/bin/systemctl reload nginx # 重载比 restart 更友好
# 若必须重启sudo /usr/bin/systemctl restart nginx
echo "Nginx 操作完成"
"""
}
}
}
post {
success { echo "🎉 h5 项目 - 主节点部署+从节点同步+Nginx重启全部完成" }
failure { echo "❌ h5 项目 - 部署/同步流程失败,请排查问题后重试" }
}
}