From c182574917d523aeff634e93bbbe8671def190cf Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Mon, 29 Dec 2025 15:21:35 +0800 Subject: [PATCH] Jenkins build --- Jenkinsfile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5c3d7dc..908bb3b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,7 +41,6 @@ pipeline { steps { script { def workspace = sh(script: "pwd", returnStdout: true).trim() - echo "当前工作空间路径: ${workspace}" // 确保路径正确 @@ -51,8 +50,20 @@ pipeline { sh "chmod -R 755 ${workspace}" sh "chown -R jenkins:jenkins ${workspace}" - // 使用更健壮的Docker命令 - sh """docker run --rm -v ${workspace}:/app -w /app node:18-alpine sh -c 'ls -la && if [ -f package.json ]; then npm install && npm run build; else echo "package.json not found"; exit 1; fi'""" + // 使用绝对路径挂载工作目录到容器中,并确保所有命令都在容器内执行 + sh '''docker run --rm -v "${PWD}:/app" -w /app node:18-alpine sh -c " + echo \"Current directory contents:\" + ls -la + echo \"Checking for package.json:\" + if [ -f \"package.json\" ]; then + echo \"package.json found, proceeding with build\" + npm install + npm run build + else + echo \"package.json not found\" + exit 1 + fi + "''' } } }