Introduction
In today’s software development world, delivering high-quality applications quickly and reliably is paramount. To achieve this, organizations are increasingly adopting Continuous Integration and Continuous Deployment (CI/CD) pipelines. These pipelines automate the building, testing, and deployment phases, enabling developers to streamline their workflows and deliver software with efficiency and consistency.
In this blog post, we will explore the process of setting up a robust CI/CD pipeline for Node.js applications using Jenkins and Docker. These powerful tools provide a seamless integration of automation, containerization, and orchestration, empowering developers to accelerate their development cycles and ensure the smooth delivery of Node.js applications.
Overview of Jenkins:
Jenkins is an open-source automation server widely used for building, testing, and deploying software applications. It provides a wide range of plugins and integrations, making it highly customizable and suitable for various programming languages and technologies. Jenkins enables developers to automate repetitive tasks, collaborate with teams, and establish robust CI/CD pipelines.
Prerequisites:
Here I will be deploying the application on the same node where jenkins is running so here are few things make sure are installed on your server.
- Node and Npm
- Docker & docker-compose
- Git
- Give permissions to Jenkins to run docker using velow command
sudo usermod -a -G docker jenkins
Step 1: Fork this repository from here
Step 2: Log into server and create ssh-keygen to connect jenkins with github.
step 3: Once key is created then head over to github and add your ssh keys.
Step 4: Next install github-integration plugin in jenkins.
Go to Manage Jenkins > Plugins > Available Plugins. Search for github integration and click on install without restart. Once done check whether it is enabled or not by navigating into installed plugins.
Step 5: Go to your repository setting add webhook to trigger jenkins.
It should appear like this once webhook is added.
Step 6: Go to Jenkins > create a new Freestyle Project and configure the job.
Under General check the github project and add the github url
Select git in source code management, add github url and add main in branches to build.
Click on add credentials and select ssh username with private key.
Add your ssh key and click add
Select GitHub hook trigger for GITScm polling under build trigger.
Select execute shell in build steps and docker-compose commands.
Step 7: Click on apply and save. As everything is done now make changes in repository and it will automatically trigger your jenkins job.
Conclusion:
Congratulations 🎉, you have successfully created jenkins CICD pipeline to deploy your nodejs application which will be triggered via webhook when any developer pushes new code in github repository.