Posts Jenkins Pull Files from Github Automatically when Files are Commited to Github
Post
Cancel

Jenkins Pull Files from Github Automatically when Files are Commited to Github

In this post, I am going to write about how to interact jenkins and github so that whenever files are commited to github, it will trigger jenkins to pull the files from github. To install jenkins server on CentOS7, please refer: Install Jenkins on CentOS7

In this post, we need

  1. A jenkins server, with required packages installed.
  2. github repository, public or private. For simplicity, I will use public repository.

Let’s start with installing necessary packages for jenkins server.

1
yum install git

jenkins

Get ready a github repository. For simplicity, I just have a readme file for testing later.
jenkins

Install plugins for jenkins server since it needs to interact with github.
jenkins
jenkins
Click available, then filter for github.
jenkins
Then scroll down to find GitHub Integration, check it and click.
jenkins
Jenkins will now start installing the plugin, check the box at bottom to restart jenkins server.
jenkins
jenkins

Jenkins server will restart after installation, you will be prompted to login jenkins server again. Now we make a jenkins project, before that, we need to get the url of the github repository which to interact with jenkins server first.
jenkins

Now start to create jenkins project.
jenkins
Click ok at bottom once is done.
jenkins

Check github project and post the copied url, please note the .git at the end of url is removed!
jenkins
Here, do not remove the .git at the end of the url.
jenkins
The check means that to notify jenkins server whenever the repository previously set was modified.
jenkins
Jenkins server are done configuring, next we start to configure github settings.
jenkins
Click on Add webhook.
jenkins
Enter the url of jenkins server, must follow by github-webhook/.
jenkins
Please make sure your jenkins server’s 8080 port is accessible by github webhook servers. Github ip ranges. To modify firewall in CentOS7, please refer: CentOS7 firewall-cmd Cheat Sheet. If everything is setup correctly, you will see a green tick as picture shown below.
jenkins

Now everything is setup, we can start to test the process. The idea is whenever codes in github is committed, github will automatically push a notification to trigger jenkins server to pull files from github, so we manually modify the readme file and commit it to trigger the notification.
jenkins
jenkins

Switch to jenkins homepage right after committed on github repository, you will see a job is on queue.
jenkins

Then the queue start to build. Click on it will lead to buld page.
jenkins
jenkins

Click on Output then all the build process will be shown.
jenkins

After build, click on Workspace to confirm jenkins has pull the updated file from github repository.
jenkins
jenkins
jenkins

Next:
Files Update to Server Through Jenkins with SSH

This post is licensed under CC BY 4.0 by the author.