Jenkins Tomcat WAR Deployment |Video upload date:  · Duration: PT12M4S  · Language: EN

Step by step guide to build a WAR with Maven and deploy to Tomcat from Jenkins for automated CI CD

Intro

So you built a Java web app and now you need to shove a WAR into Tomcat without setting your hair on fire. This guide shows how to use Jenkins to build a WAR with Maven and deploy it to Tomcat in a repeatable way. It covers the Jenkins setup Maven packaging pipeline artifact handling deploying via Tomcat manager or SSH and basic verification and rollback steps. Warning about fate is optional.

Prepare Jenkins and Tomcat environment

Before you try to automate everything and feel clever do a few sensible things first. On the Jenkins host install the Maven plugin and the Tomcat deploy plugin then add a service account for Tomcat manager or an SSH user for file copies. Configure your Java and Maven tool locations in Jenkins so builds do not fail for reasons that make you cry.

Checklist

  • Install Jenkins plugins for Maven and Tomcat deployment
  • Add credentials in Jenkins credentials store for Tomcat manager or SSH key
  • Set Java and Maven tool locations under Jenkins global tools

Create a build job or pipeline to produce the WAR

Use a declarative pipeline for repeatability and version control. The goal is simple run mvn clean package so Maven produces a WAR in the standard target folder. If you use a freestyle job then call Maven with the same goal and archive the produced WAR as a job artifact.

Example Jenkinsfile

pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps {
        checkout scm
      }
    }
    stage('Build') {
      steps {
        sh 'mvn clean package'
      }
    }
    stage('Archive') {
      steps {
        archiveArtifacts 'target/*.war'
      }
    }
    stage('Deploy') {
      steps {
        // either use tomcat deploy plugin or scp to webapps
        // see notes below for both approaches
      }
    }
  }
}

Archive or store the WAR artifact

Make the WAR a first class object in your pipeline. Use archiveArtifacts so downstream stages can pick it up and you have a last known good copy if the new build turns into a gremlin.

Deploy the WAR to Tomcat

Pick one of these approaches depending on your environment and security policy.

Using Tomcat manager

  • Install and configure the Tomcat deploy plugin in Jenkins
  • Use stored Jenkins credentials for the manager account so secrets are not in logs
  • The plugin can deploy the WAR directly to Tomcat and replace the running context

Using SSH or file copy

  • Copy the WAR into the Tomcat webapps folder via scp or rsync
  • Optionally touch the webapps folder to trigger auto deployment or restart the service
  • Use your Jenkins SSH credentials or an agent with keys so nothing is pasted into console logs

Verify deployment and add rollback or health checks

Do not trust your deploy like you trust autopilot. Add a smoke test step that calls a health endpoint or checks the application status. If the health check fails then stop promoting the new build and roll back to the previous artifact.

Verification ideas

  • Use curl from a Jenkins agent to hit a health path and assert a 200 response
  • Check Tomcat manager status if you used the manager plugin
  • Run functional smoke tests that exercise a quick path through the app

Rollback strategies

  • Keep the previous WAR archived and copy it back to webapps if the new one fails
  • Keep context folders intact so you can reattach the old version quickly
  • Use blue green or canary patterns if downtime or risk tolerance requires it

Tips for CI CD and automation

  • Make credentials scoped and rotate them periodically
  • Prefer declarative pipelines so changes live in source control
  • Archive artifacts and tag builds so you can trace which WAR was deployed and when
  • Automate health checks and alerts so humans only get involved when the magic fails

Wrapping up

You now have a practical path to build a WAR with Maven in Jenkins archive the artifact and deploy it to Tomcat via the manager or SSH. Add smoke tests and a rollback plan and you will sleep a little better at night. If that fails try coffee or more monitoring.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.