Deploying your war file from Jenkins to Tomcat

At my company we’re currently moving away from developing large desktop applications to developing smaller web applications. Changing our build-test-deploy processes is also part of that transition. After using Jenkins for a long time merely for continuous integration, I wanted to see what it takes to set up a continuous deployment pipeline. In this short post I’ll describe the steps to extend a Jenkins job to automatically deploy a built war file to a Tomcat instance. In future posts I intend to also elaborate on adding automated tests using Cucumber and or Selenium to the Jenkins build.

Step 0. Prerequisites

For the next steps I assume that you already have Tomcat up and running, you also have Jenkins up and running, have administrator privileges, and you have set up a job in Jenkins that produces a war file.

Step 1. Install Jenkins plugin

Open your favorite browser and navigate to Jenkins. Log in and select “Manage Jenkins” followed by “Manage Plugins”. Select the “Available” tab, locate the “Deploy to container” plugin and install it.

Step 2. Edit tomcat-users.xml

In order for Tomcat to accept remote deployments, you have to add a user with the role manager-script. To do so, edit the file ../conf/tomcat-users.xml and add the following line:

Step 3. Edit the Jenkins job

Back in Jenkins, go to your job and select “Configure”. Next, scroll down to the bottom of the page to the “Post-build Actions”. Select the option “Deploy war/ear to a container” from the “Add post-build action” dropdown button. Fill in the new fields, e.g.:


For WAR/EAR files you can use wild cards, e.g. **/*.war.
The context path is the context path part of the URL under which your application will be published in Tomcat.
Select the appropriate Tomcat version from the Container dropdown box (note that you can also deploy to Glassfish or JBoss using this Jenkins plugin).
For the manager’s user name and password just copy over what you’ve entered in the tomcat-users.xml file.
The Tomcat URL is the base URL through which your Tomcat instance can be reached.
Finally, don’t forget to save the configuration.

Step 4. Run the Job project and verify the end results

Schedule a build for your job in Jenkins. If you check out the log file you should see one or more lines near the end indicating that the war file has been deployed, e.g.:

Deploying /home/maven/hudson/hudson-work/jobs/MyWebApp/workspace/trunk/target/MyWebApp-1.0-SNAPSHOT.war to container Tomcat 7.x Remote
  Redeploying [/home/maven/hudson/hudson-work/jobs/MyWebApp/workspace/trunk/target/MyWebApp-1.0-SNAPSHOT.war]
  Undeploying [/home/maven/hudson/hudson-work/jobs/MyWebApp/workspace/trunk/target/MyWebApp-1.0-SNAPSHOT.war]
  Deploying [/home/maven/hudson/hudson-work/jobs/MyWebApp/workspace/trunk/target/MyWebApp-1.0-SNAPSHOT.war]
Finished: SUCCESS

If you check the logfiles in Tomcat (catalina.out) you should also see that your application has been succesfully deployed.

Lastly, if you point your browser to the URL and context path you’ve specified in the job configuration in Jenkins (e.g., http://your-server:8080/mywebapp), you should be able to open your freshly deployed application.



16 Replies to “Deploying your war file from Jenkins to Tomcat”

  1. I have done the above settings…till the build its working fine..After that I’m getting the below message.
    [INFO] Installing D:\Workspace\guestbook-web\pom.xml to C:\Users\30199870\.m2\repository\com\objectdb\tutorial\web\Guestbook\1.0\Guestbook-1.0.pom
    [INFO] ————————————————————————
    [INFO] ————————————————————————
    [INFO] Total time: 2.544s
    [INFO] Finished at: Mon Mar 30 16:10:05 IST 2015
    [INFO] Final Memory: 9M/17M
    [INFO] ————————————————————————
    [JENKINS] Archiving D:\Workspace\guestbook-web\pom.xml to com.objectdb.tutorial.web/Guestbook/1.0/Guestbook-1.0.pom
    [JENKINS] Archiving D:\Workspace\guestbook-web\target\Guestbook.war to com.objectdb.tutorial.web/Guestbook/1.0/Guestbook-1.0.war
    channel stopped
    Finished: SUCCESS
    The war file is not getting deployed to the container.

    1. i did same n got success result,
      please check your war file path,it should be correct.
      you need to mention path from work space directory.

  2. Hi, i get the message below:Started by user admin
    Building in workspace D:\Jenkins\workspace\JenkisTest01
    Updating at revision ‘2015-06-18T14:13:33.013 +0800’
    At revision 5
    no change for since the previous build
    Deploying D:\Jenkins\workspace\JenkisTest01\release1forJenkins\wheatfield\target\wheatfield-1.0.0-SNAPSHOT.war to container Tomcat 6.x Remote
    but after 1 hours, it still show me uploading, not finished, the WAR file has been upload to my remote server, the file only 40MB, what can i do except wait….

  3. My query: Jenkins to auto-deploy on Tomcat
    i am new to this proceess.
    war/ear fles: which warfile need to be given, i have war both in jenkins and eclipsee.
    context path: what is this ? which location i have mention.
    i have to publish in tomcat so how to give the path

  4. Hi,I had exported a war file and kept in jenkins workspace for deployment,
    but the case is that instead of one war I have two war files for the same application.
    So how to deploy two war files for same application?
    I tried deploying two wars, but it is raising exceptions.
    please suggest any way to get out of this problem.
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

14 − 2 =