Day 24 : Complete Jenkins CI/CD Project


Today we will create a connection between Jenkins job and GitHub repository through GitHub webhook and will trigger Jenkins job automatically when any change is made to the code
What is GitHub webhook?
GitHub Webhooks are a way for GitHub to send real-time notifications to an external service when specific events occur in a GitHub repository. They allow you to automate tasks or integrate with external applications whenever changes happen in your repository.
Tasks
a. Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.
First we need to setup GitHub Integration from plugin to create connection between Jenkins and GitHub. In order to install GitHub integration plugin, go to Dashboard —→ Manage Jenkins —→ Plugins —→ Available Plugins. Search for GitHub Integration, select and click on install.
Restart Jenkins after plugin installation is complete and wait for some time
Now check in installed plugin to see if plugin is installed or not
Once the GitHub integration plugin is installed now lets setup GitHub webhook. Go to your GitHub account and select the repository which you want to use for build job.
Go to repository settings and click on Webhook
Mention the payload url as your jenkins server url ending with github-webhook
payload url : http://yourjenkinsurl:8080/github-webhook
Once the webhook url shows a green checkmark, it means your webhook is active
Now go to jenkins and configure your free style project to be integrated with github
check in your jenkins server and validate whether the github repo is visible or not
Now build your jenkins job to configure and run your application in docker container
Validate and confirm whether your application is accessible or not
Now lets make some changes in our code in github repo and see whether our job is triggered automatically. We have already configured github webhook so it will build our job automatically
We can see in console output that the job is triggered by our actions in github
Website after making the changes
You can also use docker compose command in build steps to automate image building and running container in one step
docker compose file content
docker compose command : docker compose up -d
Subscribe to my newsletter
Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
