![build-when-a-change-is-pushed-to-github-in-jenkins](https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/how-to-build-when-a-change-.png)
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.
Open your Jenkins Project
b) Under Source Code Management, check Git and set the Repository URL to point to your GitHub Repository
![](https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/github-jenkins-integration-hooks6.png)
![](https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/github-jenkins-integration-hooks6.png)
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)’
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