Home > Software design >  "EACCES: permission denied" when running npm install by jenkins and using docker agent
"EACCES: permission denied" when running npm install by jenkins and using docker agent

Time:02-12

i've created a simple nodejs project containing a Jenkinsfile with this content:

pipeline {
  agent { docker { image 'node:12-alpine' } }
  stages {
    stage('build') {
      steps {
        sh 'npm install'
      }
    }
    stage('test') {
      steps {
        sh 'npm run test'
      }
    }
  }
}

jenkins service is running by its own user named "jenkins", i've added that user to docker user group due to previous permission issues (permission denied while trying to connect to the Docker daemon) and i already have docker plugin installed in jenkins.

but when i run the build job, i get the following error and the build fails

EACCES: permission denied, mkdir '/.npm'   

if i use

agent any

in the Jenkinsfile, i don't get the mentioned error. but i want to use docker agents.

why is this happening? am i missing something ?

CodePudding user response:

The user can't write in the default cache directory, you can overwrite it using this environment variable at the beginning of your pipeline :

environment {
    NPM_CONFIG_CACHE = "${WORKSPACE}/.npm"
}
  • Related