Jenkins 部署 vue 项目 npm install 报错

用 Jenkins 部署项目时,经常报错,差不多 5,6 次报错一次

记录了2次的报错信息如下:

第一次报错:

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

第二次报错:

npm ERR! path /opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall unlink
npm ERR! Error: EACCES: permission denied, unlink '/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli'
npm ERR!  { [Error: EACCES: permission denied, unlink '/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, unlink '/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'unlink',
npm ERR!      path:
npm ERR!       '/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, unlink \'/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'unlink',
npm ERR!   path:
npm ERR!    '/opt/test_workspace/workspace/devhm5_front_h5/node_modules/.bin/uniapp-cli',
npm ERR!   parent: 'weimai-xiaochengxu' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dev_test/.npm/_logs/2019-08-06T09_57_35_402Z-debug.log
Build step 'Execute shell' marked build as failure
SSH: Connecting from host [hm5sonar]
SSH: Connecting with configuration [hm5dev_test] ...
SSH: EXEC: STDOUT/STDERR from command [cd /opt/test_workspace && /bin/bash hm5dev_front.sh h5] ...
seccuess
SSH: EXEC: completed after 200 ms
SSH: Disconnecting configuration [hm5dev_test] ...
SSH: Transferred 0 file(s)
Finished: FAILURE

因为没有定位到原因,只能手动删除 node_moudles

在各论坛找到说 "权限不够" 推荐使用: 获取最高权限

npm install --unsafe-perm=true --allow-root

可是只是偶尔出现这个问题,不是必现的,当删除掉 node_moudles 后再次部署不会报错 , 那时也没有用到最高权限

求大佬解惑 ~

阅读 8.4k
1 个回答

说明你这个机器环境,同时多个用户在使用,如果某次是root用户触发的 npm install -g 则会导致 npm 全局目录下某文件夹权限修改为root,这个时候另一个非root用户也在操作同一个 path 自然会出现权限问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏