Complete Jenkins CI/CD Project with GitHub Integration

Complete Jenkins CI/CD Project with GitHub Integration

✔️What is GitHub webhook?

Think of a Git webhook as a 📩 helpful messenger that automatically alerts and triggers actions whenever changes happen in a Git repository. It sends a message to a designated web address (URL) 📨 when things like code updates or new branches occur. This way, it simplifies teamwork and automates tasks like 🧪 testing, 🚀 deployments, and 📢 notifications, making development processes smoother and more efficient.

✔️Use Cases of GitHub WebHook

  1. Automated Continuous Integration (CI) - GitHub webhook can trigger CI pipelines upon code pushes, automatically building and testing the changes.

  2. Automated Deployments - Webhooks can initiate deployment processes to staging or production servers when new code is merged into specific branches.

  3. Issue Tracking Integration - GitHub webhook can sync issue updates to external project management tools, keeping all stakeholders informed.

  4. Notification Alerts - Webhooks can send real-time notifications to communication platforms like Slack or email when certain events occur in the repository.

  5. External Service Integration - GitHub webhooks can integrate with external services like code review tools, security scanners, or documentation generators to streamline development workflows.

✔️Setting Up a Connection Between GitHub & Jenkins

step 1: Open the Linux server and type ssh-keygen

step 2: Now redirect to cd .ssh & explore the public and private key

step 3:Now get the public key, "cat id_rsa.pub" and copy the public key.

step 4:Then open the GitHub setting page and go to SSH & GPG keys.

step 5:SSH Keys > title: Jenkins-Project and paste the ssh public key.

Set up a pipeline for a Node Todo application

step 1:Create a new item and choose a free-style project and named it "node-todo-cicd"

step 2:In the General setting provide the project description "This is a Node JS Todo App".

Now, go to Source code management to configure GitHub to Jenkins. Provide the GitHub URL where the code exists. Use the secret text option to provide credentials to Jenkins.

Kind: SSH Username with the private key

ID: github-jenkins

Description: This is for Jenkins and github integration

Username: ubuntu

Private Key: Enter directly (cat id_rsa)

Add

Now select the credentials.

step 3:Now select the branch that appears on GitHub.

step 4:Now, go to Build Steps and choose the execute shell build option.

 docker build . -t node_todo_app:latest

 docker run -p 8000:8000 -d node_todo_app:latest

step 5:Click on build and then check if the file is present in the Linux server.

step 6:check if the file is present in the Linux server.

Now the application is running and adds port 8000 in the inbound rules in the EC2 instance security group.

✔️Setting up Webhook

step 1:Go to the Manage Jenkins option from your Jenkins dashboard.

Then choose the manage plugins option --> then install a plugin for GitHub integration with Jenkins.

step 2:Install and restart Jenkins

step 3:Go to install plugins and check whether it is enabled or not.

step 4:Open the GitHub repository.

Go to “repository settings” and then to “hooks”.

Click the “Add webhook” button. Enter “<Jenkins url>/github-webhook/” Payload URL. Click on Add webhook.

The status should be OK ✅

step 5:Now in Jenkins, open the item and configure the Build Triggers for ✅GitHub Hook trigger for GITScm pooling

step 6:Now make changes in the GitHub Repor and edit any of the frontend files and commit changes. The build will run automatically and changes will be visible in the application opened on the browser.

now commit the changes

step 7:Now auto build started.

step 8:Now the application is updated in the browser as well.

step 9: Now we have to use docker-compose for the application to up and down as well.

step 10: Now the application is successfully up & running.

For another Jenkins project.

Follow me on LinkedIn to see interesting posts like this : )

linkedin.com/in/prabir-kumar-mahatha-6a0025..

Visit my git hub profile: github.com/PrabirKumarMahatha