Jenkins deploy war file to Tomcat 8

zoran jeremic picture zoran jeremic · May 22, 2016 · Viewed 39.5k times · Source

I'm running Jenkins 1.6 (and also tried with Jenkins 2.0) on the same server where I have Tomcat 8. I need to deploy Maven multimodule application to Tomcat webapp. It has two war files from submodules that has to be deployed. Deploy plugin supports Tomcat up to 7, and it's work fine. However, the problem is that I need to use Tomcat 8, since my web application is not working on Tomcat 7. Is it possible to deploy war files from Jenkins to Tomcat 8?

Answer

Praveen Kumar K S picture Praveen Kumar K S · May 23, 2016

Answer to your question

  1. Tomcat 7 deploy plugin can be used for Tomcat 8 and 9 deployment also, It will work 100%.
  2. Have to set authentication parameters with roles assigned should be set in tomcat-users.xml file (%TOMCAT8_PATH%/conf/tomcat-users.xml)
  3. Below sample code can be used for setting role based authentication in tomcat8 container.

                    <?xml version='1.0' encoding='utf-8'?>
                    <tomcat-users>
    
                        <role rolename="manager-gui"/>
                        <role rolename="manager-script"/>
                        <user username="admin" password="password" roles="manager-gui,manager-script" />
    
                    </tomcat-users>
    
  4. For Maven Authentication in this path %MAVEN_PATH%/conf/settings.xml

       <?xml version="1.0" encoding="UTF-8"?>
                <settings ...>
                    <servers>
    
                        <server>
                            <id>TomcatServer</id>
                            <username>admin</username>
                            <password>password</password>
                        </server>
    
                    </servers>
                </settings>
    
  5. Using Tomcat 7 Maven Plugin (Can be used for Tomcat 8 Deployments also)

                <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <url>http://localhost:8080/manager/text</url>
                            <server>TomcatServer</server>
                            <path>/yourappcontextpath</path>
                        </configuration>
                    </plugin>
    
  6. Deploy to tomcat can be performed any of these goals on need basis.
    mvn tomcat7:deploy
    mvn tomcat7:undeploy
    mvn tomcat7:redeploy

  7. Also, for more detailed logging you can enable java.util.logging.ConsoleHandler in logging.properties file %Tomcat_path%/conf/logging.properties.

                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = java.util.logging.ConsoleHandler
    
                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = java.util.logging.ConsoleHandler
    
                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
                            org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = java.util.logging.ConsoleHandler