简体   繁体   English

Jenkins 构建问题 - npm 错误! 您的缓存文件夹包含 root 拥有的文件

[英]Jenkins build issue - npm ERR! Your cache folder contains root-owned files

I am trying to build a small node app on my Jenkins pipeline, which is running in a virtual machine.我正在尝试在我的 Jenkins 管道上构建一个小型节点应用程序,该管道在虚拟机中运行。 cross this error:越过这个错误:

    + npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno EACCES
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 111:120 "/.npm"

Running sudo chown -R 111:120 "/.npm" doesn`t help since it says:运行sudo chown -R 111:120 "/.npm"帮助,因为它说:

chown: cannot access '/.npm': No such file or directory chown: 无法访问 '/.npm': 没有那个文件或目录

And, as per my understanding, runs in a local context, when the problem is actually from the container perspective.而且,根据我的理解,当问题实际上是从容器的角度来看时,它在本地上下文中运行。 I`ve tried to add the command above on my Docker and Jenkinsfile as well, to no avail.我也尝试在我的 Docker 和 Jenkinsfile 上添加上面的命令,但无济于事。 Below is my public repo:以下是我的公共回购:

Node app deploy on github节点应用部署在 github

npm install --cache=".YourCustomCacheDirectoryName"

works perfectly fine, reason for this is your docker user isn't allowed to write in / ( root directory ) its not that a directory already exist at /.npm its that, your script is trying to create a directory at / which is not accessible for your user you can either put工作得很好,原因是您的 docker 用户不允许写入 / (根目录)它不是目录已经存在于 /.npm 它,你的脚本试图在 / 创建一个目录您的用户可以访问,您可以输入

agent {
    docker {
      image 'node:latest'
      args '-u root:root'
    }
}

or just tell npm to use your custom cache directory或者只是告诉 npm 使用您的自定义缓存目录

I had the same issue and fixed it by setting the npm cache directory to ENV variable in Dockerfile.我有同样的问题并通过将 npm 缓存目录设置为 Dockerfile 中的 ENV 变量来修复它。

Add this to Dockerfile:将此添加到 Dockerfile:

ENV npm_config_cache /home/node/app/.npm

As far as I can remember,just updating npm version and deleting the whole project did the trick.据我所知,只需更新 npm 版本并删除整个项目就可以了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您的缓存文件夹包含根拥有的文件 - Your cache folder contains root-owned files 错误“由于 npm ERR 中的错​​误,您的缓存文件夹包含根拥有的文件!之前版本的 npm 已得到解决” - Error "Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which has since been addressed" npm 安装总是给出“您的缓存文件夹包含根拥有的文件,由于 npm 以前版本的 npm 中的错误,该错误已得到解决。” - npm install always gives 'Your cache folder contains root-owned files, due to a bug in npm previous versions of npm which has since been addressed.' 错误“您的缓存文件夹包含根拥有的文件,由于以前版本的 npm 中的错误”而“npx create-react-app example_app” - Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app" npm 安装错误并且无法更改 root 拥有的文件的所有权 - npm install error and unable to change ownership of root owned files 在 node_modules 中没有 .cache 文件夹的 npm run build - npm run build without .cache folder in node_modules Heroku 构建失败并出现 npm ERR - Heroku build failing with npm ERR npm ERR:缺少脚本; 建造; - npm ERR! missing script: build; Azure DevOps npm 构建包含本地不存在的文件 - Azure DevOps npm build contains files that don't exist locally 在 Jenkins 管道上缓存 NPM 依赖项 - Cache NPM dependencies on Jenkins pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM