In this example, we're going to push changes to our GitHub repository and run build in Jenkins server.
How it works
- User pushed local changes to GitHub.
- GitHub tells Jenkins to run build.
- Jenkins copies repository from GitHub under '/var/lib/jenkins/workspace/country' directory and runs build scripts if there are any.
You must have
git installed on your Jenkins server so run
$ sudo apt-get install git before steps below.
1. Find GitHub web hook URL in Jenkins
- Select "Manage Jenkins" menu option on the left.
- Select "Configure System" option in the list.
- Click "Advanced" button under "GitHub" section.
- Tick "Specify another hook url for GitHub configuration" tickbox, note URL
http://192.168.10.11:8080/github-webhook/ somewhere and untick it again.
2. Enable web hook URL in GitHub
- Select "Settings" tab.
- Select "Webhooks" menu option on the left.
- Click "Add Webhook" button.
- In the following screen, paste
http://192.168.10.11:8080/github-webhook/ into "Payload URL" textbox.
3. Create a new project in Jenkins
- Select "New Item" menu option on the left.
- Name it as "country".
- Click "Free Style" project and save.
- Select "Git" in "Source Code Management" section.
- Paste HTTPS address of your repository into "Repository URL" textbox.
- Click "Add" button to add GitHub login credentials and click "Add" after adding your username(email address) & password information. Make sure it is selected in drop-down option in main screen.
- Leave "Branches to build" textbox blank to build on all branches.
- Under "Build Triggers" section tick "Build when a change is pushed to GitHub" tickbox.
- Click "Save" and exit.
Commit a dummy file and push it to GitHub repository. If you check "country" project in your Jenkins GUI, you'll see a blue
#1 icon in "Build History" which means the tests passed.