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
- A jenkins server, with required packages installed.
- 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
Get ready a github repository. For simplicity, I just have a readme file for testing later.
Install plugins for jenkins server since it needs to interact with github.
Click available, then filter for github.
Then scroll down to find
GitHub Integration, check it and click.
Jenkins will now start installing the plugin, check the box at bottom to restart jenkins server.
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.
Now start to create jenkins project.
Click ok at bottom once is done.
Check github project and post the copied url, please note the
.git at the end of url is removed!
Here, do not remove the
.git at the end of the url.
The check means that to notify jenkins server whenever the repository previously set was modified.
Jenkins server are done configuring, next we start to configure github settings.
Click on Add webhook.
Enter the url of jenkins server, must follow by
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.
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.
Switch to jenkins homepage right after committed on github repository, you will see a job is on queue.
Then the queue start to build. Click on it will lead to buld page.
Click on Output then all the build process will be shown.
After build, click on Workspace to confirm jenkins has pull the updated file from github repository.