merchapp/java-mall-app-shop-admin/Jenkinsfile

100 lines
3.4 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
tools {
nodejs 'NodeJS18'
}
environment {
UNIAPP_DIR = 'java-mall-app-shop-admin'
TARGET_PLATFORM = 'h5'
OUTPUT_DIR = "${UNIAPP_DIR}/dist/build/${TARGET_PLATFORM}"
DEPLOY_PATH = '/data/nginx/www/uniapp-h5'
}
stages {
stage('拉取代码') {
steps {
checkout scm
}
}
stage('彻底清理并安装完整依赖') {
steps {
sh """
cd ${UNIAPP_DIR} || {
echo "错误:项目目录不存在!"
exit 1
}
# 彻底清理旧依赖和缓存
rm -rf node_modules package-lock.json
npm cache clean --force # 清理npm缓存解决依赖下载不完整问题
# 设置镜像源(确保国内访问稳定)
npm config set registry https://registry.npmmirror.com
# 额外配置@dcloudio私有源关键解决uni系列包下载问题
npm config set @dcloudio:registry https://registry.npmmirror.com
# 安装核心依赖指定稳定版本避免latest版本兼容性问题
npm install @vue/cli-service@5.0.8 --save-dev
npm install @dcloudio/vue-cli-plugin-uni@3.0.0 --save-dev
# 强制安装缺失的i18n模块
npm install @dcloudio/uni-cli-i18n@latest --save-dev
# 安装项目其他依赖
npm install
# 验证依赖是否安装完整
echo "检查关键模块是否存在..."
if [ ! -d "node_modules/@dcloudio/uni-cli-i18n" ]; then
echo "错误:@dcloudio/uni-cli-i18n 仍未安装成功!"
exit 1
fi
"""
}
}
stage('UniApp打包构建') {
steps {
sh """
cd ${UNIAPP_DIR}
# 再次验证命令可用性
npx vue-cli-service help | grep uni-build || {
echo "错误uni-build命令仍不可用"
exit 1
}
# 执行打包
npx vue-cli-service uni-build \
--mode production \
--platform ${TARGET_PLATFORM}
# 验证输出
if [ ! -d "${OUTPUT_DIR}" ]; then
echo "打包失败,未生成输出目录!"
exit 1
fi
"""
}
}
stage('部署到服务器') {
steps {
sh """
mkdir -p ${DEPLOY_PATH}
cp -r ${OUTPUT_DIR}/* ${DEPLOY_PATH}/
echo "部署成功!"
"""
}
}
}
post {
success { echo "打包部署成功" }
failure { echo "打包部署失败" }
}
}