We’ve already seen Jenkins Installation, Running sample Application. In this post we will be getting our hands dirty with real time Java Web application deployment in Tomcat where we will be deploying java .war file using Declarative Jenkins Pipeline.
If you’re not sure What is Jenkins than you’re probably at the wrong place and I would recommend you to go through this.
Before we deep dive into this, you must have some prerequisite to get started, such as

What is Jenkins Pipeline?
Jenkins Pipeline (or simply “Pipeline” with a capital “P”) is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. To read more about it you can go through this.
Steps:
1.Install tomcat
2.Go to /opt/tomcat
3.Change permission to 777 web app “chmod 777 /tomcat/webapp” or
4.Change the user owner “sudo chown -R ubuntu:ubuntu tomcat/”
5.Go to /opt/tomcat/bin
6../ startup.sh
7. In jenkin install sshagent plugin.
8. Generate the pipleline syntax add, credentials username with private key.
9. Add user name “ubuntu” and add private key “copy”
10. Find below jenkins declarative file
pipeline{ agent any stages{ stage("Git Checkout"){ steps{ git credentialsId: 'github', url: 'https://github.com/aditya-malviya/myweb.git' } } stage("Maven Build"){ steps{ sh "mvn clean package" sh "mv target/*.war target/myweb.war" } } stage("deploy-dev"){ steps{ sshagent(['tomcat-dev1']) { sh """ scp -o StrictHostKeyChecking=no target/myweb.war ubuntu@yourip:/opt/tomcat/webapps/ ssh ubuntu@yourip /opt/tomcat/bin/shutdown.sh ssh ubuntu@yourip /opt/tomcat/bin/startup.sh """ } } } } }
So this is how we build Java application using Jenkins Declarative Pipleline, Do revert me for any queries.