views:

484

answers:

1

I'm just getting started with CruiseControl.NET and nAnt and don't really have a good understanding of how the whole process works. We currently have most of our solutions in Visual Source 'Safe', and have the build server Label each release automatically using the AssemblyInfo file.

We're migrating our VSS projects into SVN, and have modified the project build files accordingly to check out and update the SVN respositories. What we want to achieve, is to have a copy of the source in source control, that matches exactly the version of the project being deployed.

Our SVN is set up thus:

svn://solution/  
    TRUNK/
    RELEASES/
         1.0.0/
         1.2.0/
    BRANCHES/

So when we force build our solution, with its assemblyinfo version set as 1.3.0, we want the build server to copy the TRUNK directory, into the RELEASES/1.3.0/ directory.

The SVN command is fairly simple. svn copy src/directory dst/directory. But where would I put this command, and how do I get the version number for the destination?

On the build server, this is an example of an .xml file:

    <sourcecontrol type="svn">
 <trunkUrl>svn://project/trunk</trunkUrl>
            <workingDirectory>D:\Builds\project\Src</workingDirectory>
            <executable>C:\Subversion\bin\svn.exe</executable>
 <username>sf_service_dev</username>
 <password>SFx4vi-r</password>
            <tagOnSuccess>true</tagOnSuccess>
 <cleanCopy>true</cleanCopy>
</sourcecontrol>

In the project .build file we have this (and a lot more of course):

<target name="Deploy_Release">
     <property name="fileandpathformyfile" value="${CCNetWorkingDirectory}\Bin\project.exe"/>
  <echo message="fileandpathformyfile is ${fileandpathformyfile}."/>
  <property name="ReleaseNumber" value="${fileversioninfo::get-file-version(fileversioninfo::get-version-info(fileandpathformyfile))}"/>
  <echo message="ReleaseNumber has been detected to be ${ReleaseNumber}."/>

  <!--Use version as needed-->

  <!--Create the release direcory-->
  <mkdir dir="${CCNetWorkingDirectory}\..\Releases\${ReleaseNumber}"/>
  <!--Copy stuff to the release directory-->
  <copy todir="${CCNetWorkingDirectory}\..\Releases\${ReleaseNumber}">
    <fileset basedir="${CCNetWorkingDirectory}\bin">
      <include name="*.dll" />
      <include name="*.exe" />
      <include name="*.config" />
      <include name="*.xml" />
      <include name="*.stp" />
    </fileset>
  </copy>
</target>

Now, if I want to run an SVN command to copy ${trunkURL} to ${trunkURL}/../releases/${ReleaseNumber}, how would I do this and in what file would it go? How I understand it at the moment, we either need to get the ReleaseNumber from the .build file, into the .xml file, and run an from there. Or, we need to pass through the trunkURL from the .XML to the .build, and run an svn command from the .build file.

Please help!

+3  A: 

One option is to tag (aka svn copy) on every successful build. There is actually built in functionality for this.

i see you have <tagOnSuccess> enabled true

you should also set <tagBaseUrl>svn://project/trunk/Releases</tagBaseUrl> or <tagBaseUrl>svn://project/trunk/Tags</tagBaseUrl>

The problem you may have with this is every successful build, whether forced or continuous will tag. I'm guessing you don't want to copy to Release every build.

What you could do is

  1. execute a batch file with the nAnt exec task
  2. write an if statement checking %CCNetRequestSource% environment variable for ForceBuild
  3. execute command line svn operation (CCNetWorkingDirectory will be available as environment variable, you may have to pass in release # as a parameter)

Could also checkout nantcontrib, seems to have svn task

EDIT

You may want to look at the CC.Net managing your version # via a labeller and passing it to nAnt via CCNetLabel environment variable. From what I've read you most likely want the File Labeller because the others auto generate a label for you, I personally use the iteration labeller.

The advantage to using CC.Net labeller for versioning is the build emails will show the correct release version, and I believe <tagOnSuccess> uses the label for the directory name.

Ryu
Just so you know, we have separate CC.NET config files for the continuous and release versions on the build server. Thanks for your help, that's so much easier than what I'd of thought of! Cheers
Josh Smeaton
You may want to look at the CC.Net managing your version # and passing it to nAnthttp://confluence.public.thoughtworks.org/display/CCNET/Labeller+Blocks you most likely want the File Labeller
Ryu
Can the File Labeller retrieve the version number from an AssemblyInfo file? Or does it have to contain nothing but a version number? We could easily enough generate a version.file via ant in the .build script, but would like to avoid that if the work is already done.
Josh Smeaton