From 18fa62f6be53002cd1b4dd178d81fc63a5e28226 Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Mon, 29 Dec 2025 15:41:20 +0800 Subject: [PATCH] Jenkins build --- Jenkinsfile | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 48080a0..7e089cd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,19 +45,32 @@ pipeline { // 确保路径正确 sh "ls -la ${workspace}" - sh "npm -v" - sh "npm install && npm run build" - // 修复权限问题 -// sh "chmod -R 755 ${workspace}" -// sh "chown -R jenkins:jenkins ${workspace}" -// -// // 使用绝对路径挂载工作目录到容器中,并确保所有命令都在容器内执行 -// sh 'docker run --rm -v "${PWD}:/app" -w /app node:18-alpine sh -c \'if [ -f "package.json" ]; then echo "package.json found"; npm install && npm run build; else echo "package.json not found"; exit 1; fi\'' + // 使用 Jenkins Node.js 插件 + nodejs('NodeJS-18') { + // 检查是否存在 package.json + if (fileExists('package.json')) { + echo "package.json found" - // 检查构建是否生成了 dist 目录 - sh 'ls -la' - sh 'if [ ! -d "dist" ]; then echo "ERROR: dist directory does not exist after build"; exit 1; fi' + // 安装 pnpm + sh 'npm install -g pnpm' + + // 使用 pnpm 安装依赖 + sh 'pnpm install --frozen-lockfile' + + // 构建项目 + 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 { + error('package.json not found') + } + } } } }