npm install fails in jenkins pipeline in docker
Adding the environments and setting the Home to '.' solves this as below.
pipeline { agent { docker { image 'node:8.12.0' } } environment { HOME = '.' } stages { stage('Clone') { steps { git branch: 'master', credentialsId: '121231k3jkj2kjkjk', url: 'https://myserver.com/my-repo.git' } } stage('Build') { steps { sh "npm install" } } }}
from https://github.com/jenkins-infra/jenkins.io/blob/master/Jenkinsfile
docker.image('openjdk:8').inside { /* One Weird Trick(tm) to allow git(1) to clone inside of a * container */ withEnv([ /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */ 'npm_config_cache=npm-cache', /* set home to our current directory because other bower * nonsense breaks with HOME=/, e.g.: * EACCES: permission denied, mkdir '/.config' */ 'HOME=.', ]) { // your code }}
Having wasted a whole day on this issue, I found simply adding the following as an environment variable at the agent stage using the Pipeline Editor removed the problem.
'npm_config_cache=npm-cache'