merchapp/java-mall-app-shop-admin/Jenkinsfile
panjunjie f272439db8 add Jenkinsfile for Jenkins deploy
添加 jenkins 部署脚本 Jenkinsfile
2025-08-11 10:52:23 +08:00

84 lines
2.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 'NodeJS16'
}
environment {
// 主项目部署路径
DEPLOY_DIR = '/data/nginx/www/fafamall/demo'
// UniApp项目目录
UNIAPP_DIR = 'merchapp/java-mall-app-shop-admin'
// UniApp打包输出路径根据实际项目配置调整
UNIAPP_DIST = 'merchapp/java-mall-app-shop-admin/dist/build/h5'
}
stages {
stage('拉取代码') {
steps {
checkout scm
}
}
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 '''
# 进入UniApp项目目录
cd ${UNIAPP_DIR}
# 清理旧依赖和缓存
rm -rf node_modules package-lock.json
# 设置镜像源并安装依赖
npm config set registry https://registry.npmmirror.com
npm install
# 执行UniApp打包以H5为例可根据需要替换为其他平台命令
npm run build:h5
# 如需部署UniApp产物可添加部署命令示例
# mkdir -p /data/nginx/www/uniapp-shop-admin
# rm -rf /data/nginx/www/uniapp-shop-admin/*
# cp -r ${UNIAPP_DIST}/* /data/nginx/www/uniapp-shop-admin/
'''
}
}
}
post {
success {
echo '主项目及UniApp项目部署成功.'
}
failure {
echo '项目部署失败.'
}
}
}