+91 700 483 5930   +91 810 584 3520    info@scmgalaxy.com
LOGIN
Sign In or Register
Avatar
Not Registered Yet?

Join Now! It's FREE. Get full access and benefit from this site

Reset My password - Remind Me My username

Username
Password
Remember me
 
scmGalaxy logo

How to Build when a change is pushed to GitHub in Jenkins?

The GitHub plugin for Jenkins is the most basic plugin for integrating Jenkins with GitHub projects. If you are a GitHub user, this plugin enables you to:
 
  • Schedule your build
  • Pull your code and data files from your GitHub repository to your Jenkins machine
  • Automatically trigger each build on the Jenkins server, after each Commit on your Git repository
 
This saves you time and lets you incorporate your project into the Continuous Integration (CI) process.

How to Start Working with the GitHub Plugin for Jenkins
Install the Github Jenkins plugin
Go to "Manage Jenkins" --> "Manage Plugins" --> "Available" Tab --> Search for "GitHub plugin" and install it.
 
Configure the plugin with github accounts and keys
Go to "Manage Jenkins" --> "Configure System" --> Locate "Github" section and "Add Github Server".

API URL - If you server is github.com, your "API URL" would be "https://api.github.com" Otherwise if you use GitHub Enterprise, specify its API endpoint here (e.g., https://ghe.acme.com/api/v3/).

 
Credentials - You can create your own personal access token in your account GitHub settings. 
Token should be registered with scopes: Refer https://github.com/settings/tokens/new.
 
Add credentials (your Github token), Apply and "Test Connection".

 
Open your Jenkins Project
a) Check the GitHub project checkbox and set the Project URL to point to your GitHub Repository

b) Under Source Code Management, check Git and set the Repository URL to point to your GitHub Repository
c) Under Build Triggers, check the “Build when a change is pushed to GitHub” checkbox
 
4. Install the Jenkins (GitHub plugin) and set a webhook to your Jenkins machine
a) From your GitHub repository, go to Settings and then to Integrations & Services
b) Click on Add Service and add ‘Jenkins (GitHub plugin)’
c) Set the Jenkins hook URL as the URL for your Jenkins machine, and add /github-webhook/



 
Congratulations! Every time you publish your changes to Github, GitHub will trigger your new Jenkins job.
 
 
Another Approach noted by suprakash
Actually if you do the web hook settings from Jenkins -> Github plugin configuration (mentioned above), you will still see webhooks get created in github. So , above two approaches basically doing the same thing.
 
I personally like it to create webhook from Github, because in this way you don't have to share or store github user info in jenkins.
 
Steps : 1. Login into Github (with Admin) 2. Go to the repository you want to hook with jenkins 3. Click on settings tab -> webhooks & services 4. Click on Add Webhook 5. Enter payload url : like : http://:8080/github-webhook/ 6. Select content type as json 7. you are done
 
Now you do the changes and commit , you will see jenkins build get trigger automatically. Don't forget to do the settings in jenkins jobs to start the build when push code in github.

Reference
https://www.blazemeter.com/blog/how-start-working-github-plugin-jenkins
https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin
http://stackoverflow.com/questions/30576881/jenkins-build-when-a-change-is-pushed-to-github-option-is-not-working
Rate this item
(2 votes)
Rajesh Kumar

.

Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.

NEW TUTORIALS