From 3d7ab7c6affd26cdd753a2a172c99248902e7e94 Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Mon, 29 Dec 2025 15:47:36 +0800 Subject: [PATCH] Jenkins build --- Jenkinsfile | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4e20aa4..1378672 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,27 +46,40 @@ pipeline { // 确保路径正确 sh "ls -la ${workspace}" - // 使用 Jenkins Node.js 插件 - nodejs('NodeJS-18') { - // 检查是否存在 package.json - if (fileExists('package.json')) { - echo "package.json found" + // 修复权限问题 + sh "chmod -R 755 ${workspace}" + sh "chown -R jenkins:jenkins ${workspace}" + // 使用 Jenkins Node.js 插件,并确保在工作空间目录中执行 + dir(workspace) { + nodejs('NodeJS-18') { + // 检查是否存在 package.json 和 pnpm-lock.yaml + if (fileExists('package.json')) { + echo "package.json found" + if (fileExists('pnpm-lock.yaml')) { + echo "pnpm-lock.yaml found" + } else { + error('pnpm-lock.yaml not found') + } - // 使用 pnpm 安装依赖 - sh 'npm install' + // 安装 pnpm + sh 'npm install -g pnpm' - // 构建项目 - sh 'npm run build' + // 使用 pnpm 安装依赖,使用 --frozen-lockfile 确保依赖一致性 + sh 'pnpm install --frozen-lockfile' - // 检查 dist 目录是否存在 - if (!fileExists('dist')) { - error('ERROR: dist directory does not exist after build') + // 构建项目 + sh 'pnpm run build' + + // 检查 dist 目录是否存在 + if (!fileExists('dist')) { + error('ERROR: dist directory does not exist after build') + } else { + echo 'Build completed successfully, dist directory exists' + } } else { - echo 'Build completed successfully, dist directory exists' + error('package.json not found') } - } else { - error('package.json not found') } } }