What Github Webhook is?
Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.
Read About GitHub WebHooks and make sure you have CICD setup
Refer this video for the entire project
Task-01
Fork this repository:
Log in to your Jenkins instance and navigate to the dashboard.
Click on the "New Item" button in the top left corner of the screen.
Enter a name for your new pipeline and select "Freestyle project" as the project type.
Click "OK" to create your new pipeline
Configure pages opens up and add a description as I added below
And select it as GitHub project and provide the Github project url
Under the Source Code Management section and give the proper URL of your code repo.
Under the Build Triggers section choose the GitHub hook trigger for GITScm polling.
Click on apply and save
Now navigate to the Jenkins dashboard and click on Manage Jenkins > Plugins section
Click on available plugins and search for GitHub Integration then install it without restart
Now go to GitHub and open the repository that you want to integrate with Jenkins.
Click on settings > Webhook > Add Webhook and edit the payload url
with [Jenkins url followed by github-webhook]
Select send me everthing checkbox below
Click on Add webhook
Check the Active webhooks now
Now any commits made from node-todo-cicd github project will be traced by Webhook and it will automatically trigger the jenkins for build and deploment
Task-02
We have already configured the Node-todo_webhook project with all the git project urls and integrated Jenkins with Webhook in github project setting
Let's move to configuration of the project we need to run and move to build steps session and select execute run shell
Add the docker-compose commands in the dropbox
Click on apply and save
We will be auto triggering these commands for deployment by making commits in the project code in github through webhook
Open the project in GitHub repo and commit with some changes in the code
As we have Webhook it will trigger Jenkins for new changes and start the build deployment instantly.
Console output
Jenkins Integration with GITHUB
Create a freestyle project and add the description
Select it as Github project and provide the url
Under source code management select is as git and provide the code url
For credentials we need to generate ssh-keygen in Jenkins installed Ec2 instance
$ ssh-keygen
$ cd .ssh
$ cat id_rsa.pub
Copy the Public rsa key and navigate to the Github repo settings \> ssh and GPG Keys
Click on New SSH Key
Provide the title, key type and paste the rsa.pub key in the key box and click on Add ssh key
Now get back to Jenkins project configuration under Source code management > Credentials
Click on add > Jenkins
Add credentials
Kind = SSH username with private key
Description = Jenkins and Github
username = ubuntu
Private key > select enter directly > Add > Paste the private key
Click on Add
Where to find the Private key
Go to ec2 instance
$ cd .ssh
$ ls
$ cat id_rsa
Integration between Jenkins and GitHUb is done.
Select the creds now as
Go to build steps and write the docker commands
click apply and save
Click on Build Now
Console output