Required Software and OS Installed:
– DSM version: 3.1
– wget
– Jenkins
– svn
In my previous articles I described how to install SVN and how to install Jenkins on a Synology NAS DS1511+ ( or any other linux box ). This post will continue the setup of a development environment and will demonstrate how to create a post-commit SVN hook to trigger a build with Jenkins.
Your project should be already setup in Jenkins. Pressing the “Build Now” button should checkout the sources from your Repository and build & test your sources. The next step is to automate the process that every commit in your repository should ignite a new incremental build in Jenkins. We now no longer need to poll the SCM anymore and Jenkins will only set to action if there is something to do.
A way to archive this, is using a feature from SVN called hooks. Subversion’s hook scripts provide a powerful and flexible way to associate actions with repository events. The only event that is interesting for Jenkins is the commit event which often mean that new code has been added or existing code has ben altered and It’s time to test the new build.
Installing the Script
The post-commit script can be downloaded here save it as post-commit inside your PATH_TO_REPOSITORY/hooks directory. Make it executable for the svnserve.
#!/bin/sh
http://${SERVER}:${PORT}/subversion/${UUID}/notifyCommit?rev=$REV
- It is executed by the svnserve daemon when the repository has an commit event
- It connects to Jenkins and finds out if the install has “Cross Site Request protection” or not
- It than posts to a Jenkins url that triggers a new build
Testing the script can be done in the command line with two parameters. The first is the full file path to your repository, the second is the revision number to check out. an example is below where the path to the repository is /opt/svn/test and the revision number of 128:
./post-commit /opt/svn/test 128
Now check Jenkins if it is building a new build of your project, and check the log files in your repository directory called:
wget.log containing the wget output which gives feedback about the two transactions
post-compile.log Contains the retrieved url and other variables used during the process
A successful triggered event should initiate a build in Jenkins and an shows output on the wget.log as follow:
Happy Coding!
Useful links:
https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin