Steps to build and deploy a war file to tomcat server using Jenkins Freestyle Job - cloudeguru/Jenkins GitHub Wiki

## Architecture:

Below are the steps to deploy a war file to tomcat using Jenkins Freestyle job.

  1. Make sure that your Jenkins and Tomcat servers are running.
  2. Install Deploy to container plugin in the Jenkins.
  3. Install Git and Credentials Plugin in Jenkins.
  4. Configure Jenkins Credentials: Go to Jenkins dashboard -> Manage Jenkins -> Manage Credentials. Click on "Global credentials (unrestricted)" -> Add Credentials. Choose the appropriate credential type (e.g., Username with password) and provide the credentials required to access your Tomcat server. Save the credentials.
  5. Create Jenkins Freestyle Job: Click on "New Item" on the Jenkins dashboard. Enter a name for your job (e.g., "Deploy to Tomcat") and select "Freestyle project". Click "OK" to create the job.
  6. Configure Source Code Management: In the job configuration, under "Source Code Management", select "Git". Provide the URL of your GitHub repository (https://github.com/kloudblogs/Hello-World.git). Specify the branch to build (main).
  7. Configure Build Steps: Add a build step to build your Java project and generate the WAR file. As our pom.xml inside a sub directory provide maven goals as below -f spring-boot-hello-world/pom.xml clean install
  1. Add Post-Build Action to Deploy to Tomcat: Scroll down to the "Post-build Actions" section. Click on "Add post-build action" and select "Deploy war/ear to a container". WAR/EAR files: **/*.war. Context path: /kloudblogs. Containers: Choose "Tomcat 9.x" depending on your Tomcat version. Credentials: Select the credentials you configured earlier for authenticating with the Tomcat server. Tomcat URL: Enter the URL of your Tomcat server (e.g., http://host:8080) .
  1. If you getting permission denied error make sure to provide the ec2_usre or ubuntu user of your tomcat server to the tomcat installation directory. In this case our user is ubuntu and installation directory is /opt/tomcat10, so use below command sudo chown -R ubuntu:ubuntu /opt/tomcat10

Please subscribe to our Youtube Channel for videos on Cloud Computing, DevOps etc. KloudBlogs Youtube