Day 25 Task: Complete Jenkins CI/CD Project – Continued with Documentation

🔹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:
1.Log in to your Jenkins dashboard.

2.Click on “New Item” to create a new project.

3.Enter a name for your project and select “Freestyle project.” Click “OK.”
Step2: Configure Source Code Management
for private repositories:

  1. In the project configuration, scroll down to the “Source Code Management” section.

2.Select your version control system (e.g., Git).

3.Enter the URL of your GitHub repository in the “Repository URL” field.

4.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.

5.Save the project configuration.

for public repositories:
1.In the project configuration, scroll down to the “Source Code Management” section.

2.Select your version control system (e.g., Git).

3.Enter the URL of your GitHub repository in the “Repository URL” field.

4.No additional authentication is required for public repositories.

5.Save the project configuration.

Step3: Configure Github Webhooks
1.Go to your GitHub repository.

2.Click on “Settings” in the repository menu.

3.Select “Webhooks” from the left sidebar.

4.Click on “Add webhook.”

5.In the “Payload URL” field, enter the URL of your Jenkins server followed by /github-webhook/. For example: https://your-jenkins-server/github-webhook/.

6.Set the “Content type” to “application/json.”

7.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.”

8.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 with your username):

 sudo usermod -aG docker <username>
Enter fullscreen mode
Exit fullscreen mode

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 
Enter fullscreen mode
Exit fullscreen mode

This step enables Jenkins to execute Docker commands.

Step6: Configure Jenkins Build Triggers

1.In your Jenkins project configuration, scroll down to the “Build Triggers” section.

2.Check the box that says “Build when a change is pushed to GitHub.”

3.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
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Clustered hosting platform get a host.