Automation of WAR/EAR deployment using Jenkins

Application Deployment has always been on of the most tedious tasks in project development life cycle. This involves steps  like checking out the code from the Code Repository, building it using Maven/Ant and then deploying it to the remote servers. The process is more time/effort taking in case we have multiple servers like Staging,UAT,production.

Jenkins is an open source tool that helps us to automate and centralize the process of deployment.

What WIKI says about Jenkins

In this post i am going to explain how to deploy WAR to Apache Tomcat using SVN as code repository and Maven as build WAR tool.

Step 1 : Configure Jenkins

Jenkins comes bundled as WAR file so you need to deploy it to an Application Server. I used Apache Tomcat version 7.0.32. Below are the steps.

1.1. Start the tomcat

1.2. Deploy the jenkins.war Download location for jenkins.war

Note : Some server restrict the size of war file to be uploaded and you get the common error while deploying it from the Tomcat UI Manager. Below is how i resolved it.

a. Open the file $CATELINA_HOME\webapps\manager\WEB-INF web.xml

b. Look out for the below entry, Size 61316110 worked just fine for me

<!– 50MB max –>

c. Restart Tomcat

1.3.  Go to the URL http://locahost:8080/jenkins ( Replace local host with the IP of your server )

1.4.  Add Deploy to container Plugin this can be done using the Plugin Manager feature of Jenkins. This plugin will be used for deployment of the war that we will build using Jenkins.

1.5.  Provide Maven Location to Jenkins – Jenkins interacts with Maven to build code that requires maven. Follow the below steps.

a. Download Maven Link for download

b. Place it on the server and copy its path

c  Go to URL http://localhost:8080/jenkins/configure ( Replace localhost with the IP of your server )

d. Provide name ( Any random name ) and location of your maven.

Configure System [Jenkins] 2013-07-16 12-50-02

Step 2 : Configure Tomcat for build deployment

We need to configure the server where we will be deploying our build ( This server can be same or different then the one where Jenkins is running ). This involves creating a user on tomcat and assigning him with manager-script role.

Just add the below lines under the node <tomcat-users></tomcat-users> to tomcat-users.xml file  and restart the server. This file is located in the conf folder of tomcat.

<role rolename=”manager”/>
  <role rolename=”admin”/>
  <user username=”harpreet” password=”harpreet” roles=”standard,manager,admin,manager-gui,manager-script” />

Step 3  –  Create a Job on Jenkins

3.1  Click On “New Job”

3.2 Enter the name for the Job

3.3 Select Build a maven2/3 project

New Job [Jenkins] 2013-07-16 12-59-18

3.4  Look out for section Source Code Management, select Subversion and provide the SVN url of project you will be prompted for your SVN credentials.

Paxcel Config [Jenkins] 2013-07-16 13-03-373.5   Look out for Build section Provide Maven build parameters e g . clean package.

Paxcel Config [Jenkins] 2013-07-16 13-06-26

3.6 : Add a post build action that will deployed the war file to remote tomcat server.  Follow the below steps

a . Click on button “Add post build action”

b. Select the option ” Deploy war/ear to a container”

C . Enter war file name and path

Important :  For every job Jenkins create a folder named as workspace in the jobs folder, this path needs to relative to workspace. Upon successful build war is copied in this folder, and deploy plugin picks it from here. If the war is not in this folder, or you failed to provide the correct path.War will not be deployed to the server.

d Enter the server detail and credential of the user that we created on the tomcat in above steps

Paxcel Config [Jenkins] 2013-07-16 13-14-20

3.7 : Save the job and hit “Build Now”,  Check the logs by clicking the ball icons on the left side of the screen.

TalentHuntV2 [Jenkins] 2013-07-16 13-16-46

There will be log traces like you have for Maven, when you build it using eclipse or command line args.

And few jenkins log signifying the deployment like below :

Deploying /home/gagan/.jenkins/jobs/TalentHuntV2/workspace/target/TalentHunt-1.0.war to container Tomcat 7.x Remote

3.8 :  Verifying you did it correct.In case you did everything right, you can test the deployment of your project on the servers.

Step 4 ( Optional ) – Enable Auto Build

You can also configure Jenkins to build your code automatically when anyone commits the code.

4.1 Look out for section “Build Trigger” section.

4.2 Select the event that you want for build trigger. I chose that Jenkins should poll SVN for an updates. If update in code is found it will trigger the build.

For this we just need to select option”Poll SCM” and enter appropriate time, i used pattern */5 * * * * .

T2 Config [Jenkins] 2013-07-17 10-17-42

Important : For configuration of project that use artifacts from other project please do read my next blog. Building Artifacts Using Jenkins

Jenkins can help you automate a number of other processes/tasks. WAR/EAR development is the one you can start, once you are into Jenkins am sure you will be tempted to explore it further.

You can post any issues that you get in Jenkins configuration on this blog, We at Paxcel Technology will be happy to help you.

Harpreet Singh

Enterprise Java Group

Paxcel Technologies

8 thoughts on “Automation of WAR/EAR deployment using Jenkins

  1. Hi Team,

    Am a java developer, presently we are not using any build tool or jenkins. But I am trying to make complete deployment process Automatic using ANT and JENKINS.
    We are using CVS as repository and deploying manually using MyEclipse.

    So please help me how to start this process.

    Waiting for your reply..

    thanks & regards,


  2. I followed this document and successfully configured the jenkins. But I am facing issues while deploying with tomcat6, same configuration is working fine with tomcat7. Do you have any idea

  3. hi,

    Please can you confirm how to deploy to multiple servers.

    for example if i want to deploy to 100 tomcat application servers

  4. Great post.

    Somehow, my installation of Jenkins (under Tomcat 7, building on a windows server and deploying on a Linux server) automatically changes the (correct) containers info I entered in the Deploy plugin to this :

    Manager UN: C:\Users\/.ssh/id_rsa
    The password is hidden (yet seems too long compared to what I entered in the first place)
    The Tomcat URL is empty (even though I did give him the right path in the first place)

    Do you happen to know what is the cause of this behavior ?

  5. Nice post. But the problem here is , this is a tomcat hot deployment.
    And every time you do a hot deployment, the Perm size keeps on increasing.
    And after a couple of builds, there will be an Out of memory error in tomcat.
    In which case the subsequent Jenkins build also fails and someone has to manually stop and start tomcat. Is there a solution to overcome this problem?

  6. Hi Harpreet,
    I am trying to make complete deployment process Automatic using ANT and JENKINS.
    We are using CVS as repository and deploying manually using Eclipse.

    So please help me how to start this process.

    Waiting for your reply..

    thanks & regards,


Leave a Reply to amith Cancel reply

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

− five = 3

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>