add Jenkinsfile for Jenkins deploy

add Jenkinsfile for Jenkins deploy

Signed-off-by: panjunjie <46790855@qq.com>
This commit is contained in:
panjunjie 2025-08-11 01:39:17 +08:00
parent 75b4b128d8
commit fffbdce48e

56
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,56 @@
pipeline {
agent any
tools {
nodejs 'NodeJS16'
}
environment {
// 抽取部署目标路径为公共变量
DEPLOY_DIR = '/data/nginx/www/fafamall/demo'
}
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}/
'''
}
}
}
post {
success {
echo '项目部署成功.'
}
failure {
echo '项目部署失败.'
}
}
}