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.
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.
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.
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
}
}
}
}
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.
Pick one of these approaches depending on your environment and security policy.
webapps
folder to trigger auto deployment or restart the serviceDo 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.
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.