Day 25 Task: Complete Jenkins CI/CD Project - Continued with Documentation
Table of contents
🔹Task-01
Document the process from cloning the repository to adding webhooks, and Deployment, etc. as a README , go through this example
A well written readme file will help others to understand your project and you will understand how to use the project again without any problems.
Integrating Jenkins Freestyle Project with GitHub Webhooks
This guide will walk you through the process of integrating your Jenkins Freestyle project with GitHub webhooks. This integration will allow Jenkins to automatically build and deploy your project whenever changes are pushed to your GitHub repository.
Prerequisites:
Before you begin, ensure that you have the following:
A Jenkins server set up and running.
Install Docker and Docker Compose
A GitHub repository where your project's source code is hosted.
Step1: Create a Jenkins Freestyle Project:
Log in to your Jenkins dashboard.
Click on "New Item" to create a new project.
Enter a name for your project and select "Freestyle project." Click "OK."
Step2: Configure Source Code Management
for private repositories:
In the project configuration, scroll down to the "Source Code Management" section.
Select your version control system (e.g., Git).
Enter the URL of your GitHub repository in the "Repository URL" field.
If your repository is private, you'll need to set up authentication using SSH keys or personal access tokens. Configure this in the "Credentials" section.
Save the project configuration.
for public repositories:
In the project configuration, scroll down to the "Source Code Management" section.
Select your version control system (e.g., Git).
Enter the URL of your GitHub repository in the "Repository URL" field.
No additional authentication is required for public repositories.
Save the project configuration.
Step3: Configure Github Webhooks
Go to your GitHub repository.
Click on "Settings" in the repository menu.
Select "Webhooks" from the left sidebar.
Click on "Add webhook."
In the "Payload URL" field, enter the URL of your Jenkins server followed by
/github-webhook/
. For example:https://your-jenkins-server/github-webhook/
.Set the "Content type" to "application/json."
In the "Which events would you like to trigger this webhook?" section, choose the events that should trigger the webhook. Typically, you'll select "Just the push event."
Click "Add webhook" to save your webhook configuration.
Step4: Add Current User to Docker Group
Open a terminal and run the following command to add the current user to the Docker group (replace
<username>
with your username):sudo usermod -aG docker <username>
This step allows you to use Docker without
sudo
privileges.
Step5: Add Jenkins to Docker Group
To allow Jenkins to use Docker, you need to add the Jenkins user to the Docker group. Run the following command:
sudo usermod -aG docker jenkins
This step enables Jenkins to execute Docker commands.
Step6: Configure Jenkins Build Triggers
In your Jenkins project configuration, scroll down to the "Build Triggers" section.
Check the box that says "Build when a change is pushed to GitHub."
Save the project configuration.
Step7: Test the Intergration
Push a change to your GitHub repository (e.g., make a code commit).
Visit your Jenkins dashboard.
You should see your Jenkins project automatically triggered by the GitHub webhook.
Monitor the build progress and view build logs in the Jenkins dashboard.
To update your project, execute the following commands in your Jenkins project's "Execute Shell" build step:
docker-compose down docker-compose up -d --build
Congratulations! You've successfully integrated your Jenkins Freestyle project with GitHub webhooks. Now, every time you push changes to your GitHub repository, Jenkins will automatically build and deploy your project.
For any issues or further customization, refer to the Jenkins documentation or GitHub webhooks documentation.