Reputation: 19320
I’ve deployed the latest Jenkins WAR to a Tomcat 6 server on this flavor of Linux …
[daveaip-30-888-22-999 ~]$ uname -a
Linux ip-30-888-22-999 4.1.7-99.99.amzn1.x86_64 #1 SMP Mon Sep 14 23:20:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
I have a job that builds a Gradle project. After the build has succeeded, I want to copy the newly-produced WAR file to the Tomcat 6 directory. I have this shell script as an additional build step …
cp ./build/libs/myproject.war /usr/share/tomcat6/webapps
The Tomcat6 webs directory has these permissions ….
[daveaip-30-888-22-999 ~]$ ls -al /var/lib/tomcat6/webapps
total 77876
drwxrwxr-x 4 tomcat tomcat 4096 Oct 23 19:52 .
But the command fails with this error …
+ cp ./build/libs/myproject.war /usr/share/tomcat6/webapps
cp: cannot create regular file ‘/usr/share/tomcat6/webapps/myproject.war’: Permission denied
What do I need to do to give Jenkins permissions to copy this file over? I don’t want to change the perms of the directory to 777.
Edit: In response to the answer given, I added a "whoami" into the build script ...
whoami
cp ./build/libs/myproject.war $CATALINA_HOME/webapps
And the output was
+ whoami
tomcat
+ cp ./build/libs/myproject.war /usr/share/tomcat6/webapps
So I am already running under the user that is the owner of the directory.
Upvotes: 2
Views: 2234
Reputation: 24194
See which user running cp ./build/libs/myproject.war /usr/share/tomcat6/webapps
command then, you can give permission to that user.
Run this command in build
-> Shell Script
section of your job's configure
.
$ whoami // show the user, say 'xyz'
then, run this command locally from teminal to change the ownership of the directory.
$ sudo chown -R xyz: /var/lib/tomcat6/webapps // give permission to that user
If two or more users needs permission to that directory, then you can create a group
with users
, then just give the permission to that group
. see this & this
Upvotes: 2