This guide will show you how to configure a post receive hook on a Bonobo Git Server that notifies a Jenkins CI server about repository changes. This means that whenever a new commit is pushed to the Git repository, the cURL command line tool will be launched to initiate a Http request telling Jenkins to trigger a job. Bonobo Git Server is a really nice way of setting up private, remote repositories. You can get it at the project site.
Making cUrl Available to the Git Server
cUrl is a nice little command line utility that does all things Http for you.
In order to have cURL available on your server, you need to perform the following steps:
- Download cURL and extract the executable and the ca-bundle.crt certificate store to a folder of your choice, e.g. C:\cURL\ (1)
- Add the folder you have chosen to the Windows Path environment variable. To do this, open the Windows Explorer, right click on This Computer (2), select Properties and then select Advanced Settings (3). Now click on Environment Variables (4). In the following dialog, find the system variable called Path (5), select it and click on edit. Add the path to the folder containing cURL at the end of the variable (6). Remember to separate it from the previous entry with a semicolon.
Setting Up the Git Hook to Notify Jenkins
Navigate to the repository in Windows Explorer (by default, it’s relative to the IIS Website path in ~\App_Data\Repositories\<RepositoryName>)
Go to the hooks subdirectory and create an empty file with the name post-receive (yes, no extension!)
Open the file with a text editor and paste the following content:
#!/bin/sh echo Notifying Jenkins Server curl https://<YourJenkinsServer>/git/notifyCommit?url=<YourGitRepositoryUrl>
This script will be automatically executed whenever you make a push to the server, and the three lines mean the following:
The first line tells Git what type of script the file contains (/bin/sh here meaning a regular shell script)
The second line echos a message to indicate that it’s doing work (you can view the whole console output also in your Git response)
On the third line, curl is executed to perform a Http GET request to <YourJenkinsServer> that passes the Url of <YourGitRepoUrl> as query parameter, so Jenkins knows which Repository it should check for updates.
Jenkins is always listening on that endpoint. If a request hits, Jenkins will start all jobs that are configured for this Git repository.