Deploy a simple WebApp with the help of Jenkins

Shubham Kadam
3 min readApr 22, 2021

Hello folks! In this article, we will see how to deploy any web app to a server with the help of Jenkins.

Here to accomplish this task we will need access to the GitHub repository, a server where the app needs to be hosted and running Jenkins.

Let’s go ahead! and do it.

In this demo, we are using Github as an SCM tool where our code resides, whenever you will commit your code to Github the build will execute and your site will get updated accordingly.

As a first thing, we will push our code to the Github repository with the help of direct upload folder option or with the help of git init command.

Now, we will prepare a Server where a web app needs to be hosted, it might be a physical server or an instance created on any cloud platform/environment.

Once we are done with machine creation we will SSH into the server and install required software/packages also do the necessary configuration on that instance, such as ssh config, apache, and java installation.

Our SCM and Host are ready, now we will move towards the Jenkins part.

We have set up the Github repo and the Hosts machine, now as a next step, we will log in to Jenkins and will do the necessary configurations.

Log in to Jenkins and add the instance details in Manage Jenkins < Configure System < Publish over SSH something similar to the following screenshot will appear on the screen.

Now click On the “add” button in the SSH Server option.

Now add the IP address, user name, password, and other details in the required fields.

To add the password we need to tick on the checkbox in front of use password authentication, or use a different key option.

Once we are done with data filling we need to click on “Test Configuration” button in order to test the connection, if it is successful it means the connection has established successfully between Host and Jenkins.

Above steps ensures that Jenkin will share the files with the host machine over the SSH connection.

It's time to create our Jenkins Job, let's go ahead and follow the steps as below.

  1. Go to Dashboard and click on “New Item”
  2. Enter Item/Job name, select Freestyle Project and click on “Okay” button.
  3. On the next screen, there will be a page with different fields we just need to add the fields which are required for our project rest we will keep as empty.
  4. Provide a description for the project if you want, not mandatory.
  5. In the Source Code Management option click on Git and add your Github repository details there.
  6. Now in the Build Triggers option select Poll SCM from the Build Triggers option and make it every minute (* * * * * ). This simply means that it will check if there is any change in your repository every minute, whenever there is a new commit in your repo it will start the build again remotely.
  7. Check the following option Build Enviornment < Delete workspace before build starts. This ensures that whenever the build will run it will delete the old workspace.
  8. In the Build option select “Send files or execute commands over ssh” fill in the required details.

Refer to the below image for reference.

9. Click on Apply and Save.

10. SSh into your VM node and check if the files are transferred successfully.

11. Copy the external IP of your VM and paste it into the browser.

Voila! your site is up and running.

This was a simple demonstration of hosting a web app on a server with the help of Jenkins.

Stay Safe! Happy Learning!

--

--