website/Jenkinsfile
panjunjie c988f73da0 更新 Jenkinsfile
增加直接上传代码的部署方式
2025-08-11 18:49:44 +08:00

64 lines
2.1 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/website'
// 代码仓库中预编译的dist文件夹路径
DIST_PATH = 'dist'
}
stages {
stage('拉取代码含预编译dist') {
steps {
script {
// 从代码仓库拉取最新代码包含预编译的dist
checkout scm
// 验证dist文件夹是否存在
echo "验证 ${DIST_PATH} 文件夹是否存在..."
sh """
if [ ! -d "${DIST_PATH}" ]; then
echo "错误:未找到预编译的 ${DIST_PATH} 文件夹,请确认代码仓库中已包含编译产物!"
exit 1
fi
echo "${DIST_PATH} 文件夹验证通过"
"""
}
}
}
stage('部署项目复制dist内容') {
steps {
script {
echo "开始部署到目标路径:${DEPLOY_DIR}"
sh """
# 确保部署目录存在
mkdir -p ${DEPLOY_DIR}
# 清理目标目录旧文件(保留目录本身)
rm -rf ${DEPLOY_DIR}/*
# 复制dist文件夹下的所有内容到部署目录
cp -r ${DIST_PATH}/* ${DEPLOY_DIR}/
echo "部署完成:${DIST_PATH} 内容已复制到 ${DEPLOY_DIR}"
"""
}
}
}
}
// 流水线执行结果处理
post {
success {
echo "✅ 预编译dist文件夹部署成功"
}
failure {
echo "❌ 预编译dist文件夹部署失败请查看日志排查问题"
}
}
}