问题描述
在使用Jenkins构建Vue.js应用程序时,尝试在流水线的一部分中安装所有依赖项,但遇到了一些问题。以下是用户提供的输出以及流水线中的npm install部分。
错误信息如下:
+ npm install> node-sass@4.12.0 install /var/lib/jenkins/workspace/Deploy UI/node_modules/node-sass> node scripts/install.jsDownloading binary from https://github.com/sass/node-sass/releases/download/v4.12.0/linux-x64-79_binding.nodeCannot download "https://github.com/sass/node-sass/releases/download/v4.12.0/linux-x64-79_binding.node": HTTP error 404 Not FoundHint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234or configure npm proxy via npm config set proxy http://example.com:8080> node-sass@4.12.0 postinstall /var/lib/jenkins/workspace/Deploy UI/node_modules/node-sass> node scripts/build.jsBuilding: /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/UI/bin/node /var/lib/jenkins/workspace/Deploy UI/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=gyp info it worked if it ends with okgyp verb cli [gyp verb cli '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/UI/bin/node',gyp verb cli '/var/lib/jenkins/workspace/Deploy UI/node_modules/node-gyp/bin/node-gyp.js',gyp verb cli 'rebuild',gyp verb cli '--verbose',gyp verb cli '--libsass_ext=',gyp verb cli '--libsass_cflags=',gyp verb cli '--libsass_ldflags=',gyp verb cli '--libsass_library='gyp verb cli ]gyp info using node-gyp@3.8.0gyp info using node@13.1.0 | linux | x64gyp verb command rebuild []gyp verb command clean []gyp verb clean removing "build" directorygyp verb command configure []gyp verb check python checking for Python executable "python2" in the PATHgyp verb `which` failed Error: not found: python2gyp verb `which` failed at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)gyp verb `which` failed at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)gyp verb `which` failed at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:158:21)gyp verb `which` failed python2 Error: not found: python2gyp verb `which` failed at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)gyp verb `which` failed at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)gyp verb `which` failed at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:158:21) {gyp verb `which` failed stack: 'Error: not found: python2\n' +gyp verb `which` failed ' at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)\n' +gyp verb `which` failed ' at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)\n' +gyp verb `which` failed ' at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5\n' +gyp verb `which` failed ' at FSReqCallback.oncomplete (fs.js:158:21)',gyp verb `which` failed code: 'ENOENT'gyp verb `which` failed }gyp verb check python checking for Python executable "python" in the PATHgyp verb `which` failed Error: not found: pythongyp verb `which` failed at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)gyp verb `which` failed at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)gyp verb `which` failed at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:158:21)gyp verb `which` failed python Error: not found: pythongyp verb `which` failed at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)gyp verb `which` failed at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)gyp verb `which` failed at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5gyp verb `which` failed at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:158:21) {gyp verb `which` failed stack: 'Error: not found: python\n' +gyp verb `which` failed ' at getNotFoundError (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:13:12)\n' +gyp verb `which` failed ' at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:19)\n' +gyp verb `which` failed ' at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5\n' +gyp verb `which` failed ' at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5\n' +gyp verb `which` failed ' at FSReqCallback.oncomplete (fs.js:158:21)',gyp verb `which` failed code: 'ENOENT'gyp verb `which` failed }gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.gyp ERR! stack at PythonFinder.failNoPython (/var/lib/jenkins/workspace/Deploy UI/node_modules/node-gyp/lib/configure.js:484:19)gyp ERR! stack at PythonFinder.<anonymous> (/var/lib/jenkins/workspace/Deploy UI/node_modules/node-gyp/lib/configure.js:406:16)gyp ERR! stack at F (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:68:16)gyp ERR! stack at E (/var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:80:29)gyp ERR! stack at /var/lib/jenkins/workspace/Deploy UI/node_modules/which/which.js:89:16gyp ERR! stack at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/index.js:42:5gyp ERR! stack at /var/lib/jenkins/workspace/Deploy UI/node_modules/isexe/mode.js:8:5gyp ERR! stack at FSReqCallback.oncomplete (fs.js:158:21)gyp ERR! System Linux 4.15.0-1052-awsgyp ERR! command "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/UI/bin/node" "/var/lib/jenkins/workspace/Deploy UI/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="gyp ERR! cwd /var/lib/jenkins/workspace/Deploy UI/node_modules/node-sassgyp ERR! node -v v13.1.0gyp ERR! node-gyp -v v3.8.0gyp ERR! not ok Build failed with error code: 1npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! node-sass@4.12.0 postinstall: `node scripts/build.js`npm ERR! Exit status 1npm ERR! npm ERR! Failed at the node-sass@4.12.0 postinstall script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! /var/lib/jenkins/workspace/Deploy UI/.npm/_logs/2019-11-12T02_15_01_035Z-debug.log
用户还提供了package.json和流水线代码。
解决方案
请注意以下操作注意版本差异及修改前做好备份。
方案1
首先,有几个可能导致问题的原因,你可以尝试以下解决方案:
-
检查
node_modules
目录的所有者和权限是否正确。确保你的Jenkins用户具有写入该文件夹中所有文件和目录的权限。如果你在构建过程中涉及多个用户,这是一个常见问题,但在专用构建服务器上较少见。 -
检查是否安装了构建软件包的所有依赖项。例如,你的依赖项中有一个依赖于
"node-sass": "^4.12.0"
的软件包,而node-sass
又依赖于node-gyp
。而node-gyp
又依赖于Python、make
和类似gcc
的C/C++工具链。确保这些依赖项都已正确安装。
你可以在node-sass GitHub上找到更详细的故障排除指南,这可能会有所帮助。但即使你成功解决了node-sass的问题,你可能会遇到其他由于缺少依赖项而导致的软件包失败的问题。
方案2
请注意以下操作注意版本差异及修改前做好备份。
另一种方法是使用脚本或工具来控制容器的运行顺序。你可以使用docker run
命令手动控制容器的启动顺序,或者使用一些第三方工具来管理容器的依赖关系。
以下是一个简单的bash脚本示例,可以在容器A启动后启动容器B:
#!/bin/bash
# 启动容器A
docker run -d --name container_a your_image_a
# 等待容器A完全启动
while ! docker exec container_a echo "Container A is ready"; do
sleep 1
done
# 启动容器B
docker run -d --name container_b your_image_b
在这个示例中,我们首先使用docker run
命令启动容器A,并将其命名为container_a
。然后,使用一个循环来等待容器A完全启动(这里是通过在容器内运行echo
命令来测试)。一旦容器A就绪,我们再使用docker run
命令启动容器B,并将其命名为container_b
。
以上是两种可能的解决方案,你可以根据具体情况选择适合你的方法。希望能帮到你!