Skip to main content

Command Palette

Search for a command to run...

Project : Automated Web App Deployment: Jenkins & GitHub Pipeline

Updated
3 min read

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.

  1. Jenkins installed on the EC2 Instance.

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/

  1. Docker installed on the EC2 Instance.

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

sudo apt-get install docker.io

Now Let's get started.

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

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

For this project, we will be utilizing the following repository : 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).

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:

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

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

Save the configuration.

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

In case you encounter a "permission denied" error.

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

sudo usermod -aG docker jenkins
sudo service jenkins restart

Click on "Build Now" again.

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

Now click on console output.

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

Step 6 : Check your Application by accessing the following URL: <public_ip_of_ec2:8000>

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

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

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

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

Enter the payload URL: http://yourIP:8080/github-webhook/

Click on "Add webhook".

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.

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.

More from this blog

Ajay Patel

116 posts