简体   繁体   中英

Jenkins: npm EACCES: permission denied

I have the following a simple sudo npm install which keeps on failing on EACCESS error:

在此处输入图片说明

I have already tried the following on the server:

sudo chown -R jenkins /var/lib/jenkins/workspace/
sudo setfacl -R -m user:jenkins:rwx /var/lib/jenkins/workspace

But unfortunetly nothing seems to work.

Would love to hear some suggestions for what might cause the problem.

Thanks

Actually, what helped me use Jenkins with sudo rights for Ubuntu Linux was the following command:

sudo chown -R jenkins folderName
sudo setfacl -R -m user:jenkins:rwx folderName

also you need to browse to the Jenkins install in Ubuntu at

/var/lib/jenkins/workspace

Assuming you're in Home folder, you'll have to go down two levels.

cd ..
cd ..

then

cd /var/lib/jenkins/workspace

then

sudo chown -R jenkins folderName
sudo setfacl -R -m user:jenkins:rwx folderName

This fixed my "run jenkins as root" problem.

Update the .npm-global to the proper owner. I had a similar issue while deploying using Jenkins. The .npm-global folder owner was Jenkins but all the subfolder under that had root as owner. Then I changed the owner using the below command

sudo chown -R ubuntu:ubuntu .npm-global

It doesn't look like your question is a duplicate, but people have problems with installing node-sass.

The easiest way to fix your specific problem is:

sudo npm install --unsafe-perm node-sass

In my case, this issue appeared in combination with docker images while building. I had to set the npm_config_cache=npm-cache and HOME=. environment variables so npm uses the current directory to build.

Jenkinsfile:

docker.withRegistry('https://my_registry/', 'docker_user') {
    docker.image('node-agent:node-14').inside {
        withEnv([
            /* Override the npm cache directory */
            /* Reset Home dir */
            'npm_config_cache=npm-cache',
            'HOME=.',
        ]) {
            stage('NPM Build') {
                sh "rm -rf node_modules || true" // removing node_modules if existing.
                sh 'npm install'
                sh 'npm run build'
            }
        }
    }
}

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