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.