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

90 lines
2.8 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' // 使用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/demo'
}
stages {
stage('拉取代码') {
steps {
checkout scm
}
}
stage('安装完整依赖含UniApp插件') {
steps {
sh """
cd ${UNIAPP_DIR} || {
echo "错误:项目目录不存在!"
exit 1
}
# 清理旧依赖
rm -rf node_modules package-lock.json
# 设置镜像源
npm config set registry https://registry.npmmirror.com
# 安装项目基础依赖
npm install
# 关键安装UniApp核心打包插件解决uni-build不存在问题
npm install @dcloudio/vue-cli-plugin-uni@latest --save-dev
# 安装Vue CLI服务确保vue-cli-service可用
npm install @vue/cli-service@5.0.8 --save-dev
"""
}
}
stage('UniApp打包构建') {
steps {
sh """
cd ${UNIAPP_DIR}
# 验证依赖是否安装成功
echo "检查uni-build命令是否存在..."
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 "打包部署失败" }
}
}