From 5a7a610104b8450cdcafa0b02252e13ca87e4cdc Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 20:36:01 +0800 Subject: [PATCH 01/15] add Jenkinsfile for Jenkins deploy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 Jenkins 部署文件 Signed-off-by: panjunjie <46790855@qq.com> --- Jenkinsfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..44c9a1d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,47 @@ +pipeline { + agent any + + tools { + nodejs 'NodeJS16' + } + + stages { + stage('拉取代码') { + steps { + checkout scm + } + } + + stage('安装依赖') { + steps { + sh 'npm install' + } + } + + stage('构建项目') { + steps { + sh 'npm run build' + } + } + + stage('部署项目') { + steps { + // 这里根据实际情况修改部署命令 + sh ''' + # 将dist目录拷贝到Nginx或其他Web服务器 + rm -rf /data/nginx/www/fafamall/demo/* + cp -r dist/* /data/nginx/www/fafamall/demo// + ''' + } + } + } + + post { + success { + echo 'Vue项目部署成功!' + } + failure { + echo 'Vue项目部署失败!' + } + } +} \ No newline at end of file From 6afc76faba2b7e1458f2842e5e08e4c814f8b856 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 20:36:50 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 44c9a1d..fb01195 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,10 +38,10 @@ pipeline { post { success { - echo 'Vue项目部署成功!' + echo 'Vue项目部署成功' } failure { - echo 'Vue项目部署失败!' + echo 'Vue项目部署失败' } } } \ No newline at end of file From d371093c4239634adfa6b5de69ad564af598003f Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 20:48:55 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 依赖脚本 --- Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fb01195..a8f1a53 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,12 @@ pipeline { stage('安装依赖') { steps { - sh 'npm install' + ssh ''' + # 清理缓存和旧依赖 + rm -rf node_modules package-lock.json + # 重新安装依赖 + npm install --registry=https://registry.npmmirror.com # 使用国内源加速 + ''' } } From 55a21d594b872fccfca761bfd2520d579e67c985 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 20:52:19 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a8f1a53..f8353e5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,10 +15,11 @@ pipeline { stage('安装依赖') { steps { ssh ''' - # 清理缓存和旧依赖 rm -rf node_modules package-lock.json - # 重新安装依赖 - npm install --registry=https://registry.npmmirror.com # 使用国内源加速 + npm config set registry https://registry.npmmirror.com + npm install + # 确保postcss插件兼容 + npm install postcss-px-to-viewport-8-plugin@1.1.3 --save-dev ''' } } From d8168246fec91fe65b9b849d80a8c7e9b01f2f1b Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 20:55:04 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f8353e5..1f3e6ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { stage('安装依赖') { steps { - ssh ''' + sh ''' rm -rf node_modules package-lock.json npm config set registry https://registry.npmmirror.com npm install From b386cf68351350ce4617ea0fe6af00de7a873dc1 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 21:23:03 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1f3e6ad..ff519b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any tools { - nodejs 'NodeJS16' + nodejs 'NodeJS22' } stages { From 679061250d668f6ab1f4b2919a7ab65ba0c77502 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 21:43:29 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更改jenkins配置 --- Jenkinsfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index ff519b8..e26a5dc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,6 +11,13 @@ pipeline { checkout scm } } + + stage('检查Node.js版本') { + steps { + sh 'node -v' // 验证Node.js版本,应输出v22.18.0 + sh 'npm -v' // 验证npm版本,应输出对应版本(如v10.9.3) + } + } stage('安装依赖') { steps { From 220e49cfb4e1f8ae6baf638e89bc80e58c865bc1 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 21:44:21 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 Jenkins 的部署配置 --- Jenkinsfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e26a5dc..4a49a54 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,8 +14,8 @@ pipeline { stage('检查Node.js版本') { steps { - sh 'node -v' // 验证Node.js版本,应输出v22.18.0 - sh 'npm -v' // 验证npm版本,应输出对应版本(如v10.9.3) + sh 'node -v' + sh 'npm -v' } } @@ -25,7 +25,6 @@ pipeline { rm -rf node_modules package-lock.json npm config set registry https://registry.npmmirror.com npm install - # 确保postcss插件兼容 npm install postcss-px-to-viewport-8-plugin@1.1.3 --save-dev ''' } @@ -39,9 +38,7 @@ pipeline { stage('部署项目') { steps { - // 这里根据实际情况修改部署命令 sh ''' - # 将dist目录拷贝到Nginx或其他Web服务器 rm -rf /data/nginx/www/fafamall/demo/* cp -r dist/* /data/nginx/www/fafamall/demo// ''' From a79aa884d3d847438ff6edd2c5344b7887359688 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 22:03:28 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新jenkins配置 --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4a49a54..004b157 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,6 +39,7 @@ pipeline { stage('部署项目') { steps { sh ''' + mkdir -p /data/nginx/www/fafamall/demo/ rm -rf /data/nginx/www/fafamall/demo/* cp -r dist/* /data/nginx/www/fafamall/demo// ''' From 67f0cf87cb7fd79762049731dbaa807e0fe23638 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 22:07:21 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新部署配置 --- Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 004b157..ff67b5a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,7 +25,6 @@ pipeline { rm -rf node_modules package-lock.json npm config set registry https://registry.npmmirror.com npm install - npm install postcss-px-to-viewport-8-plugin@1.1.3 --save-dev ''' } } @@ -39,9 +38,9 @@ pipeline { stage('部署项目') { steps { sh ''' - mkdir -p /data/nginx/www/fafamall/demo/ + mkdir -p /data/nginx/www/fafamall/demo rm -rf /data/nginx/www/fafamall/demo/* - cp -r dist/* /data/nginx/www/fafamall/demo// + cp -r dist/* /data/nginx/www/fafamall/demo/ ''' } } From 3dc7da0387fd3755bd32199a9bf7ce948373700d Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Sun, 10 Aug 2025 22:26:57 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新jenkins 配置文件 --- Jenkinsfile | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff67b5a..b037011 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,11 @@ pipeline { tools { nodejs 'NodeJS22' } + + environment { + // 抽取部署目标路径为公共变量 + DEPLOY_DIR = '/data/nginx/www/fafamall/website' + } stages { stage('拉取代码') { @@ -11,13 +16,6 @@ pipeline { checkout scm } } - - stage('检查Node.js版本') { - steps { - sh 'node -v' - sh 'npm -v' - } - } stage('安装依赖') { steps { @@ -38,9 +36,10 @@ pipeline { stage('部署项目') { steps { sh ''' - mkdir -p /data/nginx/www/fafamall/demo - rm -rf /data/nginx/www/fafamall/demo/* - cp -r dist/* /data/nginx/www/fafamall/demo/ + # 公共部署逻辑(创建目录、清理、复制) + mkdir -p ${DEPLOY_DIR} + rm -rf ${DEPLOY_DIR}/* + cp -r dist/* ${DEPLOY_DIR}/ ''' } } @@ -48,10 +47,10 @@ pipeline { post { success { - echo 'Vue项目部署成功' + echo 'Vue项目部署成功.' } failure { - echo 'Vue项目部署失败' + echo 'Vue项目部署失败.' } } } \ No newline at end of file From 48e580bfd4434dddc6b71923c47d631952e324d6 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Mon, 11 Aug 2025 18:43:33 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20JenkinsfileBuild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jenkins 编译+发布配置 --- JenkinsfileBuild | 1 + 1 file changed, 1 insertion(+) create mode 100644 JenkinsfileBuild diff --git a/JenkinsfileBuild b/JenkinsfileBuild new file mode 100644 index 0000000..9d60796 --- /dev/null +++ b/JenkinsfileBuild @@ -0,0 +1 @@ +11 \ No newline at end of file From 53f5cd19ee726d3b772ad377bf12901b27ea4fea Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Mon, 11 Aug 2025 18:44:09 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20JenkinsfileBuild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JenkinsfileBuild | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/JenkinsfileBuild b/JenkinsfileBuild index 9d60796..b037011 100644 --- a/JenkinsfileBuild +++ b/JenkinsfileBuild @@ -1 +1,56 @@ -11 \ No newline at end of file +pipeline { + agent any + + tools { + nodejs 'NodeJS22' + } + + environment { + // 抽取部署目标路径为公共变量 + DEPLOY_DIR = '/data/nginx/www/fafamall/website' + } + + 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 'Vue项目部署成功.' + } + failure { + echo 'Vue项目部署失败.' + } + } +} \ No newline at end of file From c988f73da075744379b6c1b9e23890766e44eff0 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Mon, 11 Aug 2025 18:49:44 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加直接上传代码的部署方式 --- Jenkinsfile | 73 +++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b037011..56b3f8d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,56 +1,63 @@ pipeline { agent any - tools { - nodejs 'NodeJS22' - } - + // 环境变量配置 environment { - // 抽取部署目标路径为公共变量 + // 部署目标服务器路径 DEPLOY_DIR = '/data/nginx/www/fafamall/website' + // 代码仓库中预编译的dist文件夹路径 + DIST_PATH = 'dist' } stages { - stage('拉取代码') { + stage('拉取代码(含预编译dist)') { steps { - checkout scm + script { + // 从代码仓库拉取最新代码(包含预编译的dist) + checkout scm + + // 验证dist文件夹是否存在 + echo "验证 ${DIST_PATH} 文件夹是否存在..." + sh """ + if [ ! -d "${DIST_PATH}" ]; then + echo "错误:未找到预编译的 ${DIST_PATH} 文件夹,请确认代码仓库中已包含编译产物!" + exit 1 + fi + echo "${DIST_PATH} 文件夹验证通过" + """ + } } } - stage('安装依赖') { + stage('部署项目(复制dist内容)') { 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}/ - ''' + script { + echo "开始部署到目标路径:${DEPLOY_DIR}" + + sh """ + # 确保部署目录存在 + mkdir -p ${DEPLOY_DIR} + + # 清理目标目录旧文件(保留目录本身) + rm -rf ${DEPLOY_DIR}/* + + # 复制dist文件夹下的所有内容到部署目录 + cp -r ${DIST_PATH}/* ${DEPLOY_DIR}/ + + echo "部署完成:${DIST_PATH} 内容已复制到 ${DEPLOY_DIR}" + """ + } } } } + // 流水线执行结果处理 post { success { - echo 'Vue项目部署成功.' + echo "✅ 预编译dist文件夹部署成功" } failure { - echo 'Vue项目部署失败.' + echo "❌ 预编译dist文件夹部署失败,请查看日志排查问题" } } -} \ No newline at end of file +} From 7907fdcb3fb45ba6c137eac58308ba5d6c13f5f7 Mon Sep 17 00:00:00 2001 From: panjunjie <46790855@qq.com> Date: Mon, 11 Aug 2025 21:11:24 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Jenkinsfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 59 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 56b3f8d..11a17eb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,63 +1,36 @@ pipeline { agent any - // 环境变量配置 environment { - // 部署目标服务器路径 DEPLOY_DIR = '/data/nginx/www/fafamall/website' - // 代码仓库中预编译的dist文件夹路径 DIST_PATH = 'dist' } stages { - stage('拉取代码(含预编译dist)') { + stage('拉取代码并验证') { steps { - script { - // 从代码仓库拉取最新代码(包含预编译的dist) - checkout scm - - // 验证dist文件夹是否存在 - echo "验证 ${DIST_PATH} 文件夹是否存在..." - sh """ - if [ ! -d "${DIST_PATH}" ]; then - echo "错误:未找到预编译的 ${DIST_PATH} 文件夹,请确认代码仓库中已包含编译产物!" - exit 1 - fi - echo "${DIST_PATH} 文件夹验证通过" - """ - } + checkout scm + sh """ + [ -d "${DIST_PATH}" ] || { echo "错误:未找到 ${DIST_PATH} 文件夹"; exit 1; } + echo "${DIST_PATH} 验证通过" + """ } } - stage('部署项目(复制dist内容)') { + stage('部署') { steps { - script { - echo "开始部署到目标路径:${DEPLOY_DIR}" - - sh """ - # 确保部署目录存在 - mkdir -p ${DEPLOY_DIR} - - # 清理目标目录旧文件(保留目录本身) - rm -rf ${DEPLOY_DIR}/* - - # 复制dist文件夹下的所有内容到部署目录 - cp -r ${DIST_PATH}/* ${DEPLOY_DIR}/ - - echo "部署完成:${DIST_PATH} 内容已复制到 ${DEPLOY_DIR}" - """ - } + sh """ + mkdir -p ${DEPLOY_DIR} + rm -rf ${DEPLOY_DIR}/* + cp -r ${DIST_PATH}/* ${DEPLOY_DIR}/ + echo "部署完成:${DIST_PATH} → ${DEPLOY_DIR}" + """ } } } - // 流水线执行结果处理 post { - success { - echo "✅ 预编译dist文件夹部署成功" - } - failure { - echo "❌ 预编译dist文件夹部署失败,请查看日志排查问题" - } + success { echo "✅ 部署成功" } + failure { echo "❌ 部署失败" } } -} +} \ No newline at end of file