merchapp/java-mall-app-shop-admin/Jenkinsfile
2025-08-11 11:07:06 +08:00

100 lines
3.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
tools {
nodejs 'NodeJS22'
}
environment {
// 主项目部署路径
DEPLOY_DIR = '/data/nginx/www/fafamall/demo'
// UniApp项目子目录
UNIAPP_SUB_DIR = 'merchapp/java-mall-app-shop-admin'
// UniApp打包输出目录相对子目录的路径
UNIAPP_DIST_RELATIVE = 'dist/build/h5'
}
stages {
stage('拉取代码') {
steps {
checkout scm
echo "代码检出完成,当前工作目录: ${env.WORKSPACE}"
}
}
// 主项目构建部署(保持不变)
stage('安装主项目依赖') {
steps {
sh '''
rm -rf node_modules package-lock.json
npm config set registry https://registry.npmmirror.com
npm install
'''
}
}
stage('构建主项目') {
steps {
sh 'npm run build'
}
}
stage('部署主项目') {
steps {
sh '''
mkdir -p ${DEPLOY_DIR}
rm -rf ${DEPLOY_DIR}/*
cp -r dist/* ${DEPLOY_DIR}/
'''
}
}
// UniApp项目打包在子目录中执行
stage('UniApp项目打包') {
steps {
sh '''
echo "进入UniApp项目目录: ${UNIAPP_SUB_DIR}"
cd ${UNIAPP_SUB_DIR} || {
echo "错误UniApp项目目录 ${UNIAPP_SUB_DIR} 不存在!"
exit 1
}
# 显示当前目录以确认
pwd
# 清理旧依赖
rm -rf node_modules package-lock.json
# 安装依赖
npm config set registry https://registry.npmmirror.com
npm install
# 执行打包H5平台可根据需要修改为其他平台
npm run build:h5
# 验证打包结果
if [ ! -d "${UNIAPP_DIST_RELATIVE}" ]; then
echo "错误UniApp打包失败未找到输出目录"
exit 1
fi
# 如需部署UniApp产物可添加以下命令
# UNIAPP_DEPLOY_DIR="/data/nginx/www/uniapp-admin"
# mkdir -p ${UNIAPP_DEPLOY_DIR}
# rm -rf ${UNIAPP_DEPLOY_DIR}/*
# cp -r ${UNIAPP_DIST_RELATIVE}/* ${UNIAPP_DEPLOY_DIR}/
'''
}
}
}
post {
success {
echo '主项目及UniApp项目打包部署成功'
}
failure {
echo '项目构建或部署失败'
}
}
}