3
votes

I need to execute npm install command without sudo but i got this error in my Jenkins job when i tried to execute this command this is the error console message:

+ npm install

npm WARN [email protected] requires a peer of grunt@>=1.0.1 but none was installed. npm WARN [email protected] No repository field. npm WARN [email protected] No license field. npm ERR! Linux 3.13.0-32-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" npm ERR! node v5.1.0 npm ERR! npm v4.0.2 npm ERR! path /var/lib/jenkins/workspace/mmm/node_modules/.staging npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, mkdir '/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging'] npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging' } npm ERR! npm ERR! Please try running this command again as root/Administrator.

Anyone khow how to execute this command without sudo?

3

3 Answers

2
votes

I think you need to change to access of the directory for which you are getting error by using chmod command .change it in such a way that Jenkins user is able to create directory

0
votes

thanks @pushpendra chouchan : Fixed by :

sudo chown -R [jenkins-user] /user/local/lib/node_modules/
sudo chown -R [jenkins-user] /user/local/bin/
sudo chown -R [jenkins-user] /user/local/lib/share/
0
votes

the answer is to find here: Run shell command in jenkins as root user?

jenkins user is per default not a sudoer(https://wiki.archlinux.org/index.php/sudo#Using_visudo). So its not possible to add sudo before a command.

you can try to add jenkins to sudoers but this wasnt working for me. i did it that way from the link i added.

make changes in jenkins config file /etc/default/jenkins (for most of the linux distributions) or /etc/sysconfig/jenkins (for redhat/centOS distribution)