Overview
When you create a project in pulse™, a trigger will be set up for you to start a build when the project source code is changed. This trigger works by polling the SCM for changes at regular intervals (every 5 minutes by default). This is a zero-setup way to get builds triggered on code changes, however, it is not always the best method. For example:
- If your SCM server is heavily-loaded, polling may further stress it.
- If you pull in code from another repository using svn:externals, you may want to trigger a build when the external repository changes.
Both of these situations can be handled by triggering pulse™ from a Subversion post-commit hook.
Subversion Hooks
Briefly, Subversion hooks are scripts that are executed when a certain event occurs in the repository. A post-commit hook is executed after a commit to the repository, and is thus ideal for detecting code changes and triggering builds. Hook scripts are located in the hooks subdirectory of a repository. By default, this directory includes template (.tmpl) files for each of the hooks. To activate the post-commit hook, you need to rename the template:
- On Unix-like systems, remove the .tmpl extension. Also, ensure the file has execute permission on.
- On Windows systems, change the extension to .bat.
The hook itself is a script that receives the repository path and committed revision as arguments. It needs to be modified to invoke the Python script attached to this page with those arguments as described below.
For more information on managing hooks, see http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html#svn.reposadmin.create.hooks
.
Triggering Builds
To trigger a build in pulse™ from a script, you can use the Remote API. A Python script that takes a Subversion repository path and revision as arguments and triggers a build if a certain project has changed is attached to this page (trigger-pulse.py
). To use this script, download it and save it on your Subversion server. You will need to edit the script to match your Pulse installation (instructions are given in the script itself). Also ensure that the script has execute permission on.
To tie it all together, edit the Subversion post-commit hook to call the Python script. For example, on Unix-like systems: