Integrate Jenkins with Github (Public repo)

Integrate Jenkins with Github (Public repo)

One of the simple and interesting tools in DevOps is Jenkins. Another tool which is generally used is Github, which has one of the biggest open source community, is no more required to explain. In this blog, we will see how to trigger Jenkins job from a commit to your public Github repository. To setup Jenkins build trigger on private Github repository checkout this blog. So let’s begin….

If you are coming to this blog you must have already installed Jenkins. After working on Jenkins for more than a year now, I found out a lot of interesting facts about Jenkins and one of them is that there are multiple ways you can install Jenkins but the best way is using the command line installation.

Prerequisite:

Jenkins should be installed and the initial Jenkins setup should be done, such that you can see the Jenkins dashboard. Your dashboard will look a bit different from mine as I have already created a Jenkins job and installed a few plugins which you can see on the left side of the image below.

Jenkins Dashboard

Jenkins setup for Public Repository:

  • Open your Github profile and click on creating a new repository.
Creating a Github Repository

After you are done putting above things while creating the repository click on Create repository. A new repository will get created.

  • Install the Github plugin from the Manage plugins inside Jenkins. Go to Manage Jenkins -> Manage Plugins -> Available/ Installed. Check the Github Integration Plugin after clicking on Installed Plugins. If you are not able to find it check-in available maybe it is already installed due to the initial setup.
Github Integration Plugin
  • Click on new item -> Freestyle project -> ok.
Freestyle project
  • Go to General -> Github Project. Give your project URL
Github Project URL
  • Source Code Management -> Git. By default, it will take the master branch.
Source Code Management
  • Build Triggers -> GitHub hook trigger for GITScm polling
Build Triggers
  • Build -> Execute Shell. Put echo “Shreyak” inside the text input and press Save.

Github setup for Public Repository:

  • Open your Github repository which you created and go to settings. Click on Hooks and press Add Webhook. After you are done with this follow the below image configuration and press Add webhook (green button). Now the Github webhook is also set. This configuration works if your Jenkins has a public IP address. Otherwise, use ngrok to create one for your localhost.
Setup web hook on Github

Yeah, that’s petty much it. Now make a commit to your Github Repository and you will be able to see the Jenkins job getting triggered. Try it out and let me know if everything works for you.

Ask your questions below and I will try to answer as many of them.

Have Fun ……