Tuesday, October 27, 2015

Deploying project war file from Jenkins to Tomcat

Step 0. Prerequisites
I assume that we already Tomcat, Jenkins up and running and have administrator privileges along with to 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. site: https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin
Step 2. Edit tomcat-users.xml of Tomcat to create user for
To deploy war file in tomcat we need a tomcat user who has this permission. For that we 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. Create a new Jenkin Job
In Jenkin we would required to have “Deploy war/ear to a container” this option from “Add post-build action” dropdown button. By Default this option is not available in Jenkin. To have this option we had already deployed “Deploy to container” plugin. site: https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin
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.:
jenkins-tomcat
Image_1
For WAR/EAR files we can use wild cards, e.g. **/*.war.
else we need to give the path like "target/NAME_OF_OUR_WAR_FILE.war"
The context path is the context path part of the URL under which your application will be published in Tomcat. i.e. in our case it is gwt-maven-plugin
Select the appropriate Tomcat version from the Container dropdown box.
Add the user name and password for the manager’s user name and password that we had entered in the tomcat-users.xml file.
The Tomcat URL is the base URL through which your Tomcat instance can be reached.
Image_2

save the configuration
Step 4. Run the Job and check catalina out log and we can see the new build is deployed just access the build and reconfirm everything is working fine.(e.g., http://localhost:8181/gwt-maven-plugin), we should be able to open our freshly deployed application.

No comments: