jenkins-with-webhook

 ////////////////

https://linuxdady.com/how-to-integrate-jenkins-with-webhook/

https://linuxdady.com/how-to-setup-jenkins-server/

///////////////////

How to integrate jenkins with webhook

In this tutorial we are going to integrate jenkins with webhook. But before doing integration we should know concept of webhook like what is webhook and why we should use it? What are the use cases of webhook in our infra? Let’s clear all these doubts one by one.

How to integrate jenkins with webhook

What is webhook?

Webhook is nothing it’s just a feature of our code management tool like Bitbucket, Gitlab, GitHub etc. I think it’s not clear still let move deeper with real time scenario suppose your developer is writing their code and they want CI/CD (Continuous Integration / Continuous deployment) means they want to test their code at every commit. If they are doing 5-6 commit in a day then it’s OK, we can do it manually but let’s suppose they are doing 500 plus commit per day then doing deployment at every commit become hectic or frustrating task. So, with the help of webhook we can automate such kind of task.

What does webhook?

When developers commit their code into git and push at GitHub or any other code management tool then webhook will generate a trigger and will inform to jenkins pull latest changes. After pull the latest changes  build and deploy that changes at application server. This is real time use of webhook means when developers commit their changes then webhook alert to jenkins then further process will occur automatically.

Pr requisite of jenkins integration with webhook?

  • We should have pre-configured jenkins server.
  • Install GitHub integration plugin in Jenkins for GitHub. If using Bitbucket and Gitlab install plugin accordingly.   
  • A code management tool like Bitbucket, Gitlab, GitHub etc.

Main function of webhook

Then main function of webhook as soon as developer commit their changes and push at their changes on code management tool like Bitbucket, GitHub jenkins immediately pull their changes and do all task automatically like compiling, code review, testing code coverage packaging deployment etc.

How to integrate jenkins with webhook

If we want to integrate jenkins server with webhook. We have to do some setting. First install GitHub integration plugin.

GitHub integration plugin

After installation of GitHub plugin open your project and copy your project URL. As shown in fig for better understanding.

GitHub project URL

After copy the project URL go to Jenkins dashboard and click on –> your job/project name –> configure. When above step will complete it will show dashboard which will look like below. Select here –> GitHub project then copy Project URL and scroll down.

GitHub repo URL

Move at next step and go –> Source Code Management –> click on Git and copy Your repository URL here. For better understanding have a look of below image.

Now again scroll down and got to build trigger and check option for hook. This will receive trigger for GitHub at every new commit or push and build automatically.

Set build trigger

Generate jenkins token 

From jenkins end we have done all basic setting but for communication between GitHub and Jenkins we have to generate a token that will work like a password. So, click on your username like in my case it’s linuxdady then go to –> Configure and generate a new token and copy that token.

integrate jenkins with webhook

Now at GitHub end we have to add only that token into webhook. So, go to –>Setting –> Webhooks.

[Click & Read:– How to install and use Jenkins in production infra]

[Click & Read:–  How to create jenkins jobs for beginners]

integrate jenkins with webhook

Click on Add webhook and fill the details like jenkins URL and GitHub api address that will hit jenkins automatically. As shown in fig.

jenkins url details

When click on Add webhook then webhook option check becomes green that means our webhook configured properly. Otherwise there is some issue.

integrate jenkins with webhook

We have integrate jenkins with webhook properly. Now let check it working or not. Let commit and push changes into our repo after  that we will check what will happen.

commit changes

Push the changes at GitHub into that repo you have configured into jenkins in above steps.

push changes into GitHub repo

After pushing changes into your branch immediately go to Jenkins dashboard check build is automatically building or not.

integrated jenkins with webhook

Conclusion

In this tutorial we have explained how to integrate jenkins with webhook. With the help of this integration we can automate our task and we can save our manpower and their time. Here I have tried my best to explain how to integrate jenkins with webhook? If anyone have query write me in comment box, I will try my best to resolve them.

Interview question of Webhook

  • What is webhook this is favorite question of interviewer?
  • How to integrate webhook with jenkins?
  • Can we set multiple webhook ?


//////////////////////

How to setup Jenkins step by step

In this tutorial we are going to learn how to setup Jenkins server in our infra. But before installation of Jenkins set your mind about required hardware for Jenkins and how many jobs will run on your jenkins server at a time. This is important because if you will not plan your jenkins server hardware configuration then job execution and build process will impact on jenkins server.

How to setup jenkins?

Pr required hardware preferred for jenkins server in production environment

RAM : 16 GB

CPU : 2 Dual cores

JAVA : Above JDK 1.8

OS : Centos/Rhel

This hardware requirement is only a basic idea which is given on official website of jenkins. But mainly it’s depended on how many projects or job you are running  at a time. If you are running single job at time, then why 16 GB RAM. So, it depends on need.

How to install jenkins?

There are mainly two way to install jenkins. So, it’s depended on your requirement which one you want to follow. Here we will discuss both ways.

  • From yum or rpm package.
  • From .war file.

How to setup jenkins from yum repository       

As you know jenkins is written in java language so its basic requirement is java should be installed on our base machine where we are installing jenkins.

We can also install java manually by download its package from its office website. But that is time consuming so we are installing it by yum .

java installation

Java has been successfully installed in our base machine now check java version.

check java version

Jenkins package is not available in default repository of centos or redhat. So, we have to add jenkins EPEL. Let’s do it.

[Click & Read:– Jenkins server and it’s basic terminology]

[Click & Read:–  Aws application load balancer configuration step by step]

how to setup jenkins

After adding EPEL now jenkins package will be in our jenkins EPEL. So, we can simply install it with the help of yum command.

how to install jenkins

 I think you better understood how to install Jenkins server. Now just only check service is up properly or not.

jenkins server

/var/lib/jenkins is jenkins default home directory. So, have a look of it properly. Because jenkins will put all data here and jenkins config.xml file is also available here that we can change accordingly if required.

how to setup jenkins

We have competed all step how to set jenkins. Now open your browser and hit below URL from your browser. But change your server IP address according. Also check your firewall, selinux and SG if you are using  aws ec2 instance.

when you will hit above URL in your browser it will prompt for default password and will tell location where jenkins generated default password during installation.

enter password

So, go to location and copy paste password and click on –> Continue

docker default passowrd

Jenkins first time login and select option . You want to install plugin automatically or manually.

install plugins

When required plugin will installed then create jenkins dashboard login user name and password according to requirement.

how to setup jenkins

Username and password for jenkins dashboard has been created. So have a look below.

jenkins dashboard

How  to setup jenkins second way

The second way of jenkins installation is by jenkins.war file. But first you have to download package from jenkins official website and then copy .war file at your required location. The benefit of doing this is there is not internet dependency on base machine and limitation of jenkins installation by yum or rpm is only root privilege or root user can install jenkins setup. But with the help of .war file normal user can setup jenkins without any permission issue. Download package from below link.

how to setup jenkins

If you are using Linux based operating system, then simple copy below link into your terminal.

download war file

Now let’s run jenkins.war file that we have download. You can run with the help of nohup and & shown as fig. & sign will start jenkins service in the background and nohup file will record all logs. 

start jenkins from war file

Service of jenkins has been started via .war file. So take access from URL and set default password.

jenkins default passowrd

Now default password will generate where you have put your jenkins.war file. Copy that file and try to login and set your desired password. Next step will be same as above.

jenkins home directory

Conclusion

In this tutorial we have learnt how to setup jenkins server in our  IT infra from both method. We can use any method depend of our requirement. I will recommend you use jenkins.war file for installation because we can install it without internet and root user dependency. Still if you have any query let me know. I will try my best to resolve them.

Interview question on Jenkins

  1.  How to check jenkins version
  2.  What is hardware requirement for jenkins server?
  3.  What is jenkins home directory?
  4.  How we will take backup of jenkins if required?
  5.  Can we install jenkins without internet if yes how?
  6.  What is daily routine use cases of jenkins in your infra ?


////////////////////////


///////////////////////////

Comments