简体   繁体   中英

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. 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:

chown: cannot access '/.npm': No such file or directory

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. Below is my public repo:

Node app deploy on 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

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

or just tell npm to use your custom cache directory

I had the same issue and fixed it by setting the npm cache directory to ENV variable in Dockerfile.

Add this to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM