Unlocking Automation with Webhooks: Streamlining Freestyle Projects

Unlocking Automation with Webhooks: Streamlining Freestyle Projects

Introduction

Hey there, wonderful readers! 👋 Ever heard of something called a webhook? Don't worry if it sounds a bit techy – we're here to break it down for you. In today's blog, we're going to explore how webhooks can do some pretty cool stuff, like automatically deploying our project. Yep, you read that right – it's like magic! 😏🤩
Join us as we uncover webhook secrets, making your development journey smoother! 🌐🚀

What is webhook ⁉️

A webhook is a mechanism that allows one application to send real-time data to another application or service when a specific event occurs. It's a way for applications to communicate with each other in an automated and efficient manner. Webhooks are commonly used for integrating different systems and automating processes between them.

Here's how a webhook typically works:

  1. Event Occurs: A user action triggers an event, like form submission or profile update.

  2. Webhook Trigger: The app generating the event sends an HTTP POST request to a set URL.

  3. Receiving App: The recipient app, with the webhook, listens for incoming requests.

  4. Data Processing: The recipient app processes request data, often event details.

  5. Automation: Based on data, it performs actions like DB updates, notifications, or processes.

What is GitHub webhook ⁉️

A GitHub webhook is a feature provided by GitHub, a widely used platform for version control and collaboration in software development. Webhooks in the context of GitHub allow you to set up automatic notifications and triggers that are sent to external services or applications when certain events occur within a GitHub repository. This enables you to automate actions and workflows based on these events.

How GitHub Webhooks Work ⁉️

  1. Code Push: A developer adds new code to a GitHub repository.

  2. GitHub's Alert: GitHub notices the new code and sends an alert.

  3. Ping to You: GitHub pings (sends a message) to a special web address you provided earlier.

  4. Details Included: This message includes specific details about the code changes.

  5. Your Server Reacts: Your server receives the message from GitHub.

  6. Automated Response: With the code change details, your server can automatically perform tasks like testing, building, or deploying the code.

Significant:

  1. Efficient Workflow: This automation streamlines development, reducing manual work.

  2. Instant Updates: Team members get real-time updates about code changes and their effects.

  3. Seamless Collaboration: GitHub webhooks enhance teamwork by connecting code changes to automatic actions.

Task 1:

Jenkins freestyle project using GitHub webhooks ‼️

  • Fork this repository:

  • Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.

In our previous blog, we delved into the creation of a CI/CD using Jenkins. Now, let's take it a step further by integrating GitHub webhooks for enhanced automation and efficiency. If you missed our earlier guide, catch up on it here.

Step 1: Go to your Jenkins dashboard and click on the New Item button.

Step 2: Select the Freestyle project option and provide a name for your project.

Step 3: Under the Build Triggers section, select the GitHub hook trigger for Gitscm Polling*.*

Step 4: Navigate to "Settings" > "Webhooks" > "Add webhook of your forked GitHub repo.

Step 5: In the Payload URL field, enter the following URL: <jenkins_public_ip>:8080/github-webhook/.

Step 6: Click on the Add Webhook button.

Step 7: Go back to the Jenkins dashboard and click on the Build steps tab.

Step 8: In the Execute Shell section, type the command that you want to be executed after the job is built.

Step 9: Save the project.

Step 10: Make a change to the code in your GitHub repo and commit the changes.

Step 11: Within a few seconds, the job in Jenkins should start to build automatically.

Step 12: Once the job is finished, you can view the output in the console.

Task 2:

In the Execute shell, run the application using Docker Compose.
You will have to make a Docker Compose file for this Project.

Step 1: Execute a shell script to run the application using docker-compose.

docker-compose down 
docker-compose up -d --no-deps --build web

echo "code deployed successfully"

Step 2: Make some changes in your GitHub repository, and your application will automatically get started once you commit the changes.

Conclusion

From understanding webhooks to linking GitHub and Jenkins, we've unlocked the magic of automation. This powerful collaboration streamlines coding and project management. Embrace the simplicity of webhooks for efficient development!

Let's Connect:

| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
------- Let's connect! -------
|_____________|
............... \ (•◡•) / ...................
................. \ ...... / .....................
.................. ——- .......................
.................. | ... | ......................
.................. |_ . |_ ....................

Linkedin

GitHub

Twitter

Thank you for exploring my blog! Your interest is truly appreciated. 🙌