Jenkins Continuous Integration - WAR Package Deployment

· 1 min read · 213 Words · -Views -Comments

For JAVA web development, if you choose Tomcat container, it’s generally WAR package deployment

For Jenkins WAR package deployment, there are two approaches: one is installing the Deploy to container plugin, the other is writing your own shell script solution. I chose approach 2 here for two reasons:

  1. The Jenkins plugin itself has low activity, meaning if there are any issues, you’re stuck. Currently it only supports up to Tomcat 7.x
  2. The plugin uses Tomcat-manager module for direct deployment, which I believe has poor performance

So, without further ado, let’s get started!

WAR Package Transfer to Target Server

File transfer uses Publish Over SSH, here I’m transferring to /opt/deploy/war

Writing Deployment Script

  1. vi /opt/deploy/deploy.sh

  2.  #!/bin/bash
     source /etc/profile
     cd /tmp/deploy/war
     jar -xvf *.war
     rm -f *.war
     \cp -rf * /usr/local/tomcat/webapps/ROOT/
     rm -rf *
     systemctl restart tomcat
    

    Note: I’m using Centos 7.x here, so service restart uses systemctl

  3. chmod +x deploy.sh

Jenkins Build Task Configuration

Final Thoughts

Shell scripts implement the specific execution details of the build, while Jenkins provides hooks and mechanism support. This combination solves deployment and provides great flexibility. This way, we only need to focus on programming, while the tedious build and deployment work is handed over to robots, saving us a lot of time. This is the purpose of DevOps.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover