简体   繁体   中英

Jenkins installation on Linux, executing shell command gives permission denied.

I have installed jenkins on linux machine and configured it. As part of automation of build process, I want to copy my war form one directory to another. I tried doing so using the PRE BUILD ACTION and executing shell command. cp /from directory /to directory

Build fails giving permission denied. I have tried several ways by providing root level permission to the user I log into the jenkins. Nothing works.

I am not if I am giving permission to the right user or not.

Any help would be highly appreciated. Please note I am new to LINUX/UNIX.

To find out the user that is starting Jenkins, use whoami in a pre build action and look at the build log to see what user is carrying out the build scripts. It will probably be different than the user that owns the folder you are trying to get jenkins to copy the war into.

Rather than make the user that jenkins is running a root user (a security risk since now your jenkins scripts can perform privileged actions), you can add that user to the same group that the user that owns the folder is in.

Lets say I ran whoami in a jenkins script and the user turned out to be user1 , and the user that owns the folder you are trying to copy the war into, user2 . You would want to add user1 to the same group that user2 is in, and modify the folder permissions to allow modifications of people in the same group.

To add user1 to the same group as user2 :

usermod -a -G user2 user1

Then modify the permission of the folder you want to copy into:

chmod g+w /path/to/directory

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