From 5f2de7fd74714fc085b3d3fbc9d086cea86d2656 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Mon, 11 Aug 2025 16:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交 jenkins 部署脚本 --- Jenkinsfile | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2e02b13 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,62 @@ +pipeline { + agent any + + tools { + nodejs 'NodeJS16' + } + + environment { + // 抽取部署目标路径为公共变量 + DEPLOY_DIR = '/data/nginx/www/fafamall/demo' + } + + stages { + stage('拉取代码') { + steps { + checkout scm + } + } + + stage('安装依赖') { + steps { + sh ''' + echo "清理旧依赖..." + rm -rf node_modules package-lock.json + npm cache clean --force + + echo "设置国内镜像源加速..." + 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 '项目部署失败.' + } + } +} \ No newline at end of file