Table of contents
🔁CI/CD
Building and Checking (Continuous Integration): Imagine you're all working on a big puzzle together. Whenever someone adds a new puzzle piece, Jenkins steps in to make sure it fits well and looks good. This helps prevent any odd or mismatched pieces from sneaking in. If there's a problem, Jenkins raises a flag so you can fix it before things get messy.
Testing and Delivering (Continuous Deployment): Once the puzzle is complete, Jenkins helps you do some tests to make sure everything works smoothly. It's like trying out the puzzle to see if all the parts are in the right place. If anything seems off, Jenkins lets you know so you can fix it before others see the puzzle.
Guiding the Process (Pipeline Automation): Think of Jenkins as a coach helping you play a game. It breaks down the puzzle-solving into steps: first finding the right pieces, then assembling them, and finally making sure everything's working. Whenever you finish one step, Jenkins tells you to move on to the next. This helps you avoid mistakes and confusion.
So, Jenkins is like your clever friend who watches over the puzzle-making process. It makes sure the pieces fit well, tests everything to make sure it's right, and helps you follow the right steps. This way, you can build and share your puzzle (or software) without any headaches!
Hands-on💻
Fork this repo to your repository .
Follow these steps to create a jenkins job , all the steps are same except few steps that is github integration which i will be showing here
The first step is to generate a ssh key first using
ssh-keygen
As you can see , a private key (id_rsa) and a public key (id_rsa.pub) is generated.
Now go to your github account > settings > SSH and GPG keys > create
Paste the public key in the key section and click on add SSH key.
- As you can see the Authentication is generated
Now , in jenkins go to configure then go to github where u have pasted the url of github repu , under that there is crerdential section , click on add
Now add the credentials , under kind select SSH username with privatekey , give username as ubuntu (instance name) and under private key paste the private key(id_rsa) and add.
You can use cat command to see the private key
Now , go back and under credentials you can see the username that you have created recently add it .
After this step , you have to install Github Integration plugin to make this integration happen. Go to Manage jenkins > plugins > Availaable Plugin > search Github integration and install it , jenkins might restart after that.
NOW WE CAN PROCEED WITH THE PROJECT :
After adding github url and credentials and setting up the github intergration, go to build steps > execute shell and paste this. and save it just like we did in previous blog.
echo "Code Cloned" docker build . -t node-app echo "Code built..!!" # make sure you install docker compose before itself docker-compose down docker-compose up -d echo "Container is up"
Now click on build now for the exection
As you can see the build is successfull !! and the project is running
🪝Webhook
- Lets move to the interesting part
What is webhook⁉️
- When certain events occur in a GitHub repository, a webhook is used to automatically trigger actions in external systems or services. To streamline workflows and automate various tasks, webhooks are commonly used to integrate GitHub repositories with other tools, services, or systems. When a specific event occurs in a repository, such as a new commit, a pull request, or the opening of an issue, GitHub will send an HTTP POST payload to a user-specified URL. This payload contains information about the event, allowing the external system to respond appropriately.
How to setup ⁉️
Creating the Webhook:
Go to your GitHub repository.
Click on the "Settings" tab.
Select "Webhooks" from the left sidebar.
Click the "Add webhook" button.
Configuring the Webhook:
Enter the Payload URL: This is the URL of the endpoint in your communication tool that will receive the webhook payload.
(EC2 instance public ip/github-webhook)
Choose the Content type for the payload. JSON is a common choice.
Select the events that should trigger the webhook. In this case, you'd choose the "Issues" event, specifically the "Opened" event.
(select "just the push event , includes push , commit)
Optionally, you can configure other settings such as secret tokens for security.
(click on add webhook and wait till you get the green tick mark)
Now if you commit anything in your repo , jenkins will start building automatically !! (build #2 , this started automatically when i committed something new)
I hope you understood about webhooks and how to configure them and github integration as well
Make sure you go through the previous blog to understand how to setup the projectHappy Learning :D