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.



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

  1. How come there is a list of containers offered in the drop down list, when my system only has one container installed ? And why is my only installed container, Tomcat 9, not in this list ?

  2. Hi, the plugging works just fine. But if I wanna deploy a war file with “#” in the name, the plugin just obviate the character. E.g if the name is: my-app#.10.war the plugging deploy to tomcat8,7 my-app.war
    Any Idea?


  3. Hi, I´m from Brazil

    It worked for me with Tomcat use HTTP, but when change my tomcat to HTTPS the deploy not work and failed my process on Jenkins.

    How to solved?


  4. I have configured Jenkins and tomcat on my windows machine.

    does this “Deploy war/ear to a container” supports for windows as well? to deploy *.war file into C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps

    Could some please help me?

  5. I am not able to deploy on JBoss AS7, do you have an artical on JBoss also ?

  6. 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.

  7. if tomcat is running on https location.. where should we add the SSL Certs?

  8. Nice article, i have gone through it and successfully deployed my files

  9. 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

  10. 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….

  11. 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.

Comments are closed.