2

i'm trying to copy the webapp.war to the tomcat's webapp folder after the maven build on the jenkins has finished.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>copy-webapp-to-tomcat</id>
            <phase>install</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target name="Deploying webapp to Tomcat.">
                    <copy todir="${tomcat.webapps.dir}" force="true">
                        <fileset dir="${project.build.directory}">
                            <include name="*.war" />
                        </fileset>
                    </copy>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

i added the jenkins user to the tomcat group

$ id -Gn jenkins
jenkins tomcat

and my webapps folder permissions look like

drwxrwxr-x 10 tomcat tomcat 4,0K Aug 13 17:24 webapps/

after the build is completed, the copying fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (copy-webapp-to-tomcat) on project: An Ant BuildException has occured:
Failed to copy /var/lib/jenkins/workspace/project/target/webapp.war to /opt/tomcat/webapps/webapp.war due to java.io.FileNotFoundException /opt/tomcat/webapps/webapp.war (Permission denied)
[ERROR] around Ant part ...<copy todir="/opt/tomcat/webapps" force="true">... @ 4:50 in /var/lib/jenkins/workspace/project/target/antrun/build-Deploying webapp to Tomcat..xml

when i add the write permissions to the other users for the webapps folder

drwxrwxrwx 10 tomcat tomcat 4,0K Aug 13 17:24 webapps/

the copying succeeds and i get a file

-rw-r--r--  1 jenkins jenkins  22M Aug 13 17:48 webapp.war

shouldn't it be enough that the jenkins user is a member of the tomcat group and this group has the write permission for the webapps folder?

thx, kopi

kopi_b
  • 1,453
  • 3
  • 16
  • 20
  • maven war plugin do the same. Checkout https://stackoverflow.com/questions/369639/maven-copy-war-to-tomcats-webapps-directory – Vaibs Aug 13 '17 at 16:06
  • thank you for you're suggestion, Vaibs. I will keep this in mind. for now, i prefer the deploy to container plugin. – kopi_b Aug 14 '17 at 08:40

1 Answers1

2

Please research for war deployment plugin instead using copy method. It will let you deploy war file on remote servers also in future. I have done war deployment for angular application.

  1. Create a manager-script role user for your tomcat server.
  2. Install Deploy to container plugin in Jenkins
  3. Go to configuration of your Jenkins job and select option Deploy to container option in post build action.
  4. Enter all details with tomcat username and password and save configuration.
  5. Enjoy automatic war deployment in Jenkins after build process.

You can refer following link for more details

https://www.packtpub.com/mapt/book/application_development/9781783553471/4/ch04lvl1sec33/deploying-a-war-file-from-jenkins-to-tomcat

Code Spark
  • 178
  • 14
  • although i still don't know why the copying in my question doesn't work, the plugin is probably the better way to do this anyway. thanks for your answer. – kopi_b Aug 13 '17 at 21:27
  • Thanks for your feedback. I am not really expert at the command line so suggested the another way to do it. Maybe someone would add answer about the copy method you tried out. You can upvote my answer if it worked for you. – Code Spark Aug 14 '17 at 04:13
  • sorry, forgot about the upvote. it's working fine, so here it is. – kopi_b Aug 14 '17 at 08:36
  • Thank you @kopi_b. Hope it would help others also. – Code Spark Aug 14 '17 at 10:13
  • Internally all the plugins do use copy functions. But they take care of several things as well. If somebody will write his own copy code to deploy, failures will happen in certain scenarios. Instead focus on already tested things. right ? – Vaibs Sep 21 '17 at 17:38
  • @kopi_b I am a Java Developer with the work that includes jenkins deployment. My test cases failed and the source code isnt deployed to the prod. I have learned as a programmer that a plugin , extension, interface reliable to deploy will be my best choice as i dont want to learn how jenkins work or anything. But i want my work to be done. – Vaibs Sep 21 '17 at 17:42