Skip to main content

Command Palette

Search for a command to run...

Project Title: Jenkins CI/CD(Freestyle pipeline) with GitHub Integration (Deploying Node.js To-Do Application)

Updated
6 min read
Project Title: Jenkins CI/CD(Freestyle pipeline) with GitHub Integration (Deploying Node.js To-Do Application)
A

Final-year BSc IT student and DevOps Engineer with strong hands-on experience in AWS and cloud-native technologies. I focus on building, deploying, and automating reliable systems using modern DevOps practices.

I have practical experience working with Docker and Kubernetes for containerization and orchestration, Terraform and Ansible for infrastructure automation, and CI/CD pipelines using Jenkins, GitHub Actions, and AWS CodePipeline. I enjoy solving real-world problems related to deployment, scalability, and system reliability.

This documentation provides a comprehensive guide on setting up a CI/CD pipeline using Jenkins integrated with GitHub for continuous integration and deployment of a Node.js To-Do application on an AWS EC2 instance. Jenkins will automatically pull code from GitHub, build it, and deploy it using Docker.


Steps to Complete the Project:

1. Login to AWS and Create an EC2 Instance

  • Login to your AWS account through the AWS Console.

  • Launch an EC2 instance:

    • Navigate to the EC2 Dashboard and click on Launch Instance.

    • Choose Ubuntu 24.04 LTS as the operating system.

    • Select the t2.micro instance type (free-tier eligible).

    • Configure your security groups to allow SSH (port 22) access and also prepare ports 8080 (for Jenkins) and 8000 (for the web app).

    • Launch the instance and download the .pem key file for SSH access.

2. Connect to the EC2 Instance

Connect to your newly created EC2 instance using SSH.

ssh -i <your-key-file.pem> ubuntu@<instance-public-ip>

3. Update the Instance

Run the following command to update the instance with the latest package information:

sudo apt update

4. Install Java

Since Jenkins is built in Java, it requires Java to run. Install OpenJDK 17:

sudo apt install openjdk-17-jre

Verify the installation:

java -version

5. Install Jenkins

Now, let's install Jenkins, which is essential for building the CI/CD pipeline.

a) Install dependencies required for Jenkins:

sudo apt-get install -y ca-certificates curl gnupg

b) Add the Jenkins GPG key:

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null

c) Add Jenkins repository:

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null

d) Update the package list:

sudo apt-get update

e) Install Jenkins:

sudo apt-get install jenkins

f) Enable Jenkins to start on boot:

sudo systemctl enable jenkins

g) Start Jenkins:

sudo systemctl start jenkins

h) Check Jenkins status to confirm it's running:

sudo systemctl status jenkins

6. Open Jenkins in a Browser

Jenkins runs on port 8080. To access it:

  • Modify the security group of your EC2 instance to allow inbound traffic on port 8080.

  • In your browser, go to http://<instance-public-ip>:8080.

7. Unlock Jenkins

When accessing Jenkins for the first time, you'll be asked for an admin password.

  • Retrieve the initial admin password by running:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  • Copy the password and paste it into the Jenkins login screen.

8. Install Suggested Jenkins Plugins

After entering the admin password, Jenkins will prompt you to install plugins. Select Install Suggested Plugins to get essential tools.

9. Create an Admin User

After plugins installation, Jenkins will prompt you to create your admin user account. Set a username and password for future logins.

10. Create a New Jenkins Project

Now, we'll create a freestyle project for our CI/CD pipeline.

  • Click on New Item.

  • Enter a name for your project (e.g., NodeJS To-Do App).

  • Select Freestyle Project and click OK.

11. Configure GitHub Integration

In the new Jenkins project:

  • Under Source Code Management, select Git.

  • Paste the URL of your GitHub repository where your Node.js To-Do application code is hosted.

12. Generate SSH Keys for GitHub Authentication

Jenkins will authenticate with GitHub using SSH keys.

  • Run the following command on your EC2 instance to generate SSH keys:
ssh-keygen
  • Save the private key for Jenkins and use the public key for GitHub.

13. Add SSH Key to GitHub

To enable Jenkins to connect to your GitHub repository:

  • Go to GitHub Settings > SSH and GPG Keys.

  • Click on New SSH Key, provide a title, and paste the public key generated earlier.

  • Save it.

14. Add SSH Credentials in Jenkins

Back in Jenkins, under Source Code Management:

  • Click on Add Credentials.

  • Choose SSH Username with Private Key.

  • Paste the private key you generated earlier for Jenkins.

15. Configure Build Trigger for GitHub Webhook

To ensure Jenkins automatically pulls new code when changes are made on GitHub:

  • Go to Build Triggers and check GitHub hook trigger for GITScm polling.

16. Install Docker on EC2 Instance

Since we will deploy the Node.js app inside a Docker container, Docker needs to be installed on your EC2 instance.

  • Install Docker:
sudo apt install docker.io
  • Add Jenkins to the docker group:
sudo usermod -a -G docker jenkins
  • Restart Jenkins to apply changes:
sudo systemctl restart jenkins

17. Configure Build Steps

In the Jenkins project configuration, add a Build Step by selecting Execute Shell.

Paste the following Docker commands to remove any existing container, build a new image, and deploy the app:

# Remove the existing container if it exists (ignore errors)
docker rm -f <desired_name_1> || true

# Build the Docker image
docker build . -t <desired_name_2>

# Run the container
docker run --rm -d --name <desired_name_1> -p 8000:8000 <desired_name_2>

This script ensures that your application is continuously integrated and deployed from GitHub without errors.

18. Install the GitHub Integration Plugin

To fully integrate Jenkins with GitHub:

  • Navigate to Manage Jenkins > Manage Plugins.

  • Search for GitHub Integration Plugin under the Available tab and install it.

  • Restart Jenkins.

19. Configure GitHub Webhook

GitHub needs to notify Jenkins whenever new code is pushed.

  • Go to your GitHub repository settings and click on Webhooks.

  • Add a new webhook with the following details:

    • Payload URL: http://<instance-public-ip>:8080/github-webhook/

    • Content Type: application/json

  • Save the webhook and ensure it shows a green tick, indicating success.

20. Open Application Port 8000

To allow access to your deployed Node.js application:

  • Modify the security group of your EC2 instance to allow inbound traffic on port 8000.

21. Access the Application

You can now access the deployed Node.js To-Do application by navigating to:

http://<instance-public-ip>:8000

22. Continuous Integration and Deployment

Every time you push code changes to your GitHub repository, Jenkins will:

  1. Automatically pull the latest changes.

  2. Build a new Docker image.

  3. Remove any old containers.

  4. Deploy the updated application.

This ensures continuous integration and continuous deployment of your application.


Conclusion

This Jenkins CI/CD pipeline automates the entire process of building, testing, and deploying your Node.js application on AWS EC2 using Docker. With the integration of GitHub webhooks, any push to your GitHub repository will trigger Jenkins to update your live application seamlessly.


Repository Used in This Project:

By following these steps, you've successfully completed the project!


Output of My Project :

1 ) Making changes in Github repo :

2 ) Checking the Contineous Integration of code on Jenkins :

3 ) Changes is Successfully applied to Project using Github push :

4 ) Checking the Output :

5 ) Testing the Deployed Project by checking its Features :

6 ) Checking Contineous Integration is Working or NOT :

C

Hello there Interested in Passing all IT and none IT exams with no efforts PMP, azure, Salesforce, comptia, CCNA, CISCO and all others with just a click WhatsApp Link: https://wa.me/message/LKPTS55J4JT6H1 Send us a massage

No UPFRONT payment 100% pass guaranteed and pay after pass Low cost for each exam cleared 10yrs+ experience

Disclaimer: Do not Text if being certified is not your Goal No time wasters

Send us a massage now WhatsApp: WhatsApp Link: https://wa.me/message/LKPTS55J4JT6H1

K

Great job👍

1
A

Thank you 😊

1

More from this blog

Amitabh Soni

90 posts