# Complete Jenkins CI/CD Project

In this blog, we'll guide you through the process of creating a powerful CI/CD Project using the freestyle build for your Node.js application. If you've already completed Day 23, which focused on Jenkins CI/CD, you're well on your way. Now, let's take it a step further by diving into an exciting project that you can proudly add to your resume!

## **Task-1**

**<mark>Step1:</mark>**

The first step is to fork this [GitHub](https://github.com/LondheShubham153/node-todo-cicd.git) Repository. Open the repository and click on *fork* on top right as shown in the Image below, It will automatically make a copy of it in your GitHub Profile.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692053382888/1b672777-6300-4282-9025-2bb74d041e73.png align="center")

Go to your profile and click on Repositories you will see the forked repo in it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692053516350/74008406-bbeb-4b8d-b86c-59e27a0e2f6a.png align="center")

**<mark>Step2:</mark>**

Let's first start our both Jenkins Master and Jenkins Agent. Log in to the Jenkins UI and as we have stopped our Agent Its Public IP got changed, so we have to update the changed IP in the Agent configuration on the Jenkins Console.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692136340712/f05b33bb-4d80-4841-b727-d79ab1cf293c.png align="center")

**<mark>Step3:</mark>**

1. Create a **Freestyle** Project, I named it <mark>my-node-freestyle</mark>
    
2. Select the GitHub Project and paste the code URL, I want it to run on my agent only so click on "**Restrict where this project can be run**" and type your agent name.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691964318287/aa951f3f-da0a-4fbd-bcb8-e0ba3dc3fba2.png?auto=compress,format&format=webp align="left")

1. **Integrating GitHub Webhook:**  
    They trigger Jenkins to build, test, and deploy code when GitHub events like pushes and pull requests occur, enabling real-time feedback, automated testing, and efficient development and deployment processes.  
    Go to the GitHub Repository on top of it you will see *settings*, click on it and you will see *webhook* in the list click on it and hit *Add Webhook,* put the payload URL as `Jenkins-ip/github-webhook/` as shown in the image below, reload the page and it will show a green tick.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692133049124/db1fa78e-41a4-4985-aba1-e9e058b89480.png align="center")
    
2. Reload the page of github, the webhook will be active as shown by the green tick
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692135117008/f23d4345-9b98-4ce0-bdc7-993619a233b2.png align="center")
    
3. Select the **GitHub hook trigger for GITScm polling** so that our Jenkins must know about the webhook
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692132885279/dab2408b-3f9a-47f5-af55-e66a0290c58c.png align="center")
    
4. In the **Source Code Management** do the below changes
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691964388398/8d730e24-d1a2-4822-a08a-77aa0c6fd9f3.png?auto=compress,format&format=webp align="left")
    

## Task-2

**<mark>Step1:</mark>**

Creating a Dockerfile for the node project  

```yaml
FROM node:12.2.0-alpine
WORKDIR app
COPY . .
RUN npm install
RUN npm run test
EXPOSE 8000
CMD ["node","app.js"]
```

**<mark>Step2:</mark>**

Creating a docker-compse.yml file

```yaml
version: '3.9'

services:
  web:
    build: .
    ports:
      - "8000:8000"
```

**<mark>Step3:</mark>**

In the Build Steps on the Jenkins console, select execute shell and type in the below commands

```yaml
docker-compose down
docker-compose up -d --no-deps --build web
```

**<mark>Step4:</mark>**

Now just do any modification in the code on the GitHub Repository and commit it. I did the following change in `views>todo.ejs` file as shown below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692135683708/0517389f-186b-4bc4-a88b-d3b7626cce18.png align="center")

This is the screen of Jenkins before you do a commit on the GitHub Repository, there is just **1 build** which got created when I changed the docker-compose file on the GitHub

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692135837622/70b9024e-56fa-4251-ae94-2af3d185a8f5.png align="center")

**<mark>Step5:</mark>**

Now let's do a **commit** on the repository and see the Jenkins Magic. As soon as you hit commit you will see a new **build** is triggered as shown below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692135901929/6c30d972-df0c-4be5-be12-72ee8142478f.png align="center")

And when you see the Console Output of **Build Number 2**, it will show that it got triggered by GitHub push event and it is running on my dev agent as shown below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692135992632/8bae5b68-181f-49e5-af0e-9ec7a5aef0e8.png align="center")

Okay now let's check if it is working and reflecting our modified changes. But first, make sure to add an inbound rule of **port 8000** on the **agent** instance as we are exposing it from Dockerfile and docker-compose file. I have already added it, lets copy the public IP of the Agent Instance and append it with the port 8000 like <mark>54.88.127.94:8000</mark> and hit enter in a new tab. If you got the below output then my friend you have completed the Project. Happy Learning!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692136253551/00fd26f8-6325-4f53-a17c-9b6325fde9f6.png align="center")
