Declarative Jenkins Pipeline to Deploy Java Web Application.

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

  1. Jenkins Basics.
  2. Groovy Basics.
  3. What is Jenkins Pipeline
  4. How to build java app from command line.
Jenkins CI | Slack App Directory

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.


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


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

  agent any
    stage("Git Checkout"){
            git credentialsId: 'github', url: ''
     stage("Maven Build"){
            sh "mvn clean package"
            sh "mv target/*.war target/myweb.war"
          sshagent(['tomcat-dev1']) {
          sh """
          scp -o StrictHostKeyChecking=no target/myweb.war  
          ssh ubuntu@yourip /opt/tomcat/bin/
          ssh ubuntu@yourip /opt/tomcat/bin/

So this is how we build Java application using Jenkins Declarative Pipleline, Do revert me for any queries.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s