Deploying your war file from Jenkins to Tomcat
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:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<user username="tomcat" password="Tomcat" roles="manager-gui, manager-script, manager-script,
manager-status"/>
</tomcat-users>
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