Jens A. Koch

Subversion Tasks of Phing buildfile

The article shows some Subversion tasks of a Phing buildfile.
These tasks might be useful for those still working with SVN.

The tasks (1) “checking out” and (2) “updating”, deal both with a local SVN repository.

The tasks “exporting” an external (3) or local (4) repository have the purpose of getting a clean build directory without any “.svn” stuff.

The task “update repo and do local export” (5) is good for cronjob inclusion. Imagine that the next steps would be “compile” and “zip/tar.gz”.

The task “svn-lastrevision” is for fetching the revision number. You might use it for appending the product version (v1.2.3-#123).

There is also a task called “mrproper-svn-dir” – now, guess what?
Yes, it removes the export dirs for a fresh start.

Have a look and feel free to reuse. Regards, J

List of Subversion Commands

1 - svn-update : updates ${} via svn update
2 - svn-checkout : svn checkout from ${svn.repository}
3 - svn-export-from-extern: svn export from ${svn.repository}
4 - svn-export-from-local : svn export from ${}
5 - svn-up-export-local : svn-update + svn-export-from-local

    <!-- ============================================ -->
    <!-- ======          Subversion Tasks      ====== -->
    <!-- ============================================ -->

    <!-- setup the svn properties -->
    <property name="svn.path"        value="/usr/bin/svn" />                             <!-- Path to SVN -->
    <property name="svn.username"    value="YOUR_SVN_USERNAME" />                        <!-- SVN Username -->
    <property name="svn.password"    value="YOUR_SVN_PASSWORD" />                        <!-- SVN Password -->
    <property name="svn.repository"  value="" />  <!-- SVN Repository URL -->
    <!-- We are building from /trunk. Later from /tag releases!
    <property name="repository" value="${product_version}/" />

    <target name="svn-update" description="Updates ${} via svn update.">
        <echo>Performing an SVN Update</echo>
        <exec command="svn update ${}"/>

    <target name="svn-checkout" description="Checks out the external Subversion repository to the local directory ${}.">
        <echo>Performing an SVN Checkout</echo>
        <svncheckout svnpath="${svn.path}" repositoryurl="${svn.repository}" todir="${}" />

    <target name="svn-export-from-extern" description="Exports the external Subversion repository to the local export directory ${}.">
        <echo>Performing an SVN Export</echo>
        <svnexport svnpath="${svn.path}"
                   username="${svn.username}" password="${svn.password}"
                   nocache="true" force="true"
                   repositoryurl="${svn.repository}" todir="${}" />

    <target name="svn-export-from-local" description="Exports the local Subversion repository to the local export directory ${}.">
        <echo>Performing an SVN Export on local SVN Repository</echo>
        <svnexport svnpath="${svn.path}" nocache="true" force="true"
                   repositoryurl="${}" todir="${}" />

    <target name="svn-lastrevision" description="Fetches the SVN Revision Number to a Property">
        <echo>Fetching the Revision Number</echo>
        <svnlastrevision svnpath="${svn.path}" workingcopy="${}" propertyname="svn.lastrevision"/>

    <target name="mrproper-svn-dir" description="Mr.Proper will clean the SVN Export Dir">
        <echo>Removes and recreates the SVN Export Dir to have a clean copy</echo>
        <delete dir="${}" failonerror="true" verbose="false" includeemptydirs="true" />
        <mkdir dir="${}" />

    <target name="svn-up-export-local" description="Combined tasks of svn update and svn export local">
        <echo>Combined tasks of svn update and svn export local</echo>
        <phingcall target="svn-update" />
        <phingcall target="svn-export-from-local" />
Comments Off on Subversion Tasks of Phing buildfile

Comments are closed.