#
Integrate Jenkins with GitHub (using Poll SCM)
This tutorial explains to you how to integrate Jenkins with GitHub using poll SCM option.
There are 2 ways we can integrate Jenkins with GitHub:
- using a
Poll SCM strategy
: when Jenkins on a regular basis check for updates in GitHub - using a
webhook strategy
: when GitHub trigger the Jenkins job after every push in the repo
In this tutorial I prent the Poll SCM strategy method.
Prerequisites:
- we have a GitHub repository named "GitRepo1"
- we have created the application from the tutorial named Compile & Run a Java Application in Jenkins
- We have Jenkins already installed
- "HelloWorld.java" class is in the root directory of the "GitRepo1"
The steps for integrating Jenkins and GitHub using a Poll SCM strategy
are:
Info
The steps 1-5 are done in the Job Configuration of the Job I have created for the tutorial named Compile & Run a Java Application in Jenkins
Configure the Project url - take a look at the picture below:
Configure the Repository url - take a look at the picture below:
Select the branch on which we are looking at for seeing new commits:
Check "Poll SCM" and choose the polling interval:
Info
Polling interval is defined as Cron Job. You can read more on this here
- Define what Jenkins will do when it sees a new commit on the "GitRepo1" repository:
In my case Jenkins compile HelloWorld.java file and run the application.
Here we have the code for HelloWorld.java file:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Now the configuration is completed, and we can verify if all works as expected.
This could be done by modifying something in the Java code (could be directly in GitHub) and take a look in Jenkins at "Git Polling Log".
You can verify also the Job Logs and that the HelloWorld.class file is generated on Jenkins machine.