Skip to main content

JENKINS: DEPLOYING WAR FILE TO TOMCAT

Assume we have tomcat installed and running on our server. Also assume that jenkins is installed and we have a job ready or preparing artifact. We assume that copy artifact and deploy to container plugin is already installed.Otherwise install it from Manage jenkins > Manage plugins. First of all we will create a user role in tomcat for jenkins to access.For that open tomcat-users.xml file and make following changes.

#vi /opt/tomcat/conf/tomcat-users.xml

Now restart tomcat service.
#service tomcat restart

Now open jenkins. We will create a new job to copy the war file that we already prepared and deploy it in tomcat server. Here our first job is packaging job where we had build and created a war file from source code. Now we will create another job named deploy job to deploy it to tomcat container.

Under build section select Copy artifacts from another project. Now give our previous project name which is packaging job.Under Artifact to copy give **/*.war which means all war files.Here its only one.


Now under post build action select deploy war/ear to a container. Give **/*.war under WAR/EAR
 files.Leave context path as blank as it will automatically take it.Now under containers select tomcat7 since we have installed it, give credentials which we specified under tomcat-users.xml file and also the url for tomcat.



Now click save and go to our previous job packaging job.Here we will create a post build step to trigger deploy job once it is successful.For that select Build other projects under post build step and give the name of project which is deploy job.


Now trigger packaging job.We can see once the packaging job is finished automatically the deploy job will come under que and automatically it will gets triggered.





Now to check our deployment go to http://tomcat_server_ip/webapp. We can see its running.