# Project : Automated Web App Deployment: Jenkins & GitHub Pipeline

Project Description: The primary objective of this project is to automate the building, testing, and deployment process of a web application using Jenkins and GitHub. A Jenkins pipeline will be automatically triggered through GitHub webhook integration whenever there are changes made to the code repository. The pipeline will encompass essential stages, including building, testing, and deploying the application, while also providing notifications and alerts for any failed builds or deployments.

Prerequisite:

1. EC2 Instance (Ubuntu) on AWS.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690176492245/7d67cbb3-64e0-48cf-8099-5d60a2e40f4a.png align="center")

1. Jenkins installed on the EC2 Instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690177120851/87e2a613-6c95-4f4e-9247-8ad19d33d9a4.png align="center")

If you encounter any issues during the installation of Jenkins, you can refer to the following website for guidance: [https://www.jenkins.io/doc/book/installing/linux/](https://www.jenkins.io/doc/book/installing/linux/)

1. Docker installed on the EC2 Instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690177299579/d65a1dc2-fda2-4877-a9b1-f92144fa5357.png align="center")

If Docker is not already installed, you can do so by executing the following command:

```bash
sudo apt-get install docker.io
```

Now Let's get started.

Step :1 From the Jenkins Dashboard, click on "New Item".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690177607099/cb71556e-59dd-4668-bed6-2000bcc3671c.png align="center")

Step : 2 - Assign a name to your project and select "Freestyle Project".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690177703195/cfa0b7f2-d788-434d-88bc-cc10ba51577c.png align="center")

For this project, we will be utilizing the following repository : [https://github.com/patelajay745/node-todo-cicd](https://github.com/patelajay745/node-todo-cicd)

Step 3 : Provide a description for your project and in the "Source Code Management" section, select "Git". Enter the repository URL and choose the appropriate credentials. (If credentials have not been added, please add them now).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690178202492/ed645c87-ff6f-4aeb-a97e-48971c7ddfd0.png align="center")

Select the desired branch (For this project, it is "master").

Step 4 : Under "Build Steps", select "Execute shell" from the options and add the following commands:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690178392252/e698f7a3-cf14-4925-a4e0-372206692cc6.png align="center")

we have Dockerfile in our repo so we will run following command to create image and to run it.

```bash
docker build -t to-do-app .
docker run -d -p 8000:8000 to-do-app
```

Save the configuration.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690180264369/cba42cd6-b15e-4f49-a88b-2b214d49c297.png align="center")

Step : 5 Click on "Build Now" from the left panel.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690178677005/fcecffd8-3b6f-413c-8f33-6c9e229fa792.png align="center")

<mark>In case you encounter a "permission denied" error.</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690178823783/a36fa192-1626-4e58-b62b-f187d8a2541f.png align="center")

<mark>Add your Jenkins user to the Docker group by running the following commands on the EC2 console:</mark>

```bash
sudo usermod -aG docker jenkins
sudo service jenkins restart
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690178966558/3f025b7d-2315-4fd2-8c92-3a2335bb0197.png align="center")

Click on "Build Now" again.

To view the console output, click on the build number (#2).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690179159980/36d3fa55-7643-4838-bf49-324c81039a65.png align="center")

Now click on console output.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690179224164/8ab16c44-fd29-4cad-993e-fcf5adac27a7.png align="center")

If you see you success message at the very end of you console output then congratulation you have setup your CI/CD pipeline.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690179272965/66f4d3b2-0688-4744-9a10-71a6f225d55f.png align="center")

Step 6 : Check your Application by accessing the following URL: **&lt;public\_ip\_of\_ec2:8000&gt;**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690180323975/2c0996fb-1b92-4b76-b90f-705b669ba8df.png align="center")

Step 7: Setting up GitHub webhook integration: Click on "Configure" from the left panel.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690180448770/aae668be-7842-4033-a8a6-8bc4d1773275.png align="center")

Under "Build Triggers" options, select "Github hook trigger" and save the configuration.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690180516731/3fd5c3d3-71e3-43b5-b4b4-9530427e340b.png align="center")

Step 8 : If you have forked the project repository, navigate to your GitHub project settings.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182003857/b1e7181f-b804-4666-a731-a3a180d01b33.png align="center")

Click on "Webhooks" and then "Add webhook".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182047228/438edb14-74ba-40fd-a10b-73dc669d49b0.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182116985/e15dc723-c579-4244-8166-f7617474adec.png align="center")

Enter the payload URL: [`http://yourIP:8080/github-webhook/`](http://yourIP:8080/github-webhook/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182184826/77d187aa-4246-4f47-a109-90cb068b9103.png align="center")

Click on "Add webhook".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182414873/c3c96439-d56d-43fd-ab61-84d135dd4c74.png align="center")

If you see a green tick, then your URL is correct, and you have successfully implemented your GitHub webhook. Now, any changes made to your code will automatically trigger the Jenkins pipeline.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690182838761/caf2af7a-2d87-478d-afe8-25dd08593b02.png align="center")

That concludes our project. I hope you have successfully implemented your Jenkins CI/CD pipeline. If you encounter any issues, please feel free to ask your questions in the comments.
