Geeks With Blogs

News
Elton Stoneman (@EltonStoneman) IT Consultant, integration specialist, @Microsoft MVP and @Pluralsight author.

Tim asked for some more detail on using Perforce as your SCM for CruiseControl from this post, so here are some sample config files. This post may be too detailed for a general audience…

Perforce Setup – Build Server Workspace

You'll need a dedicated workspace for the build server to use – this will be used by CC.Net to check for changes and to resync. You don't need a separate user account, so it can be created with the build manager as the owner. You'll define the location to monitor in the CC.Net config, so the workspace only needs a view over the root project. So you may create a workspace called build.server with a view of //depot/… //build.server/… (while you're setting this up you can use it from your dev machine with a different root from your normal workspace, then change the host to be the build server when your scripts are finished).

CruiseControl setup - CCNet.config
 
This sample config uses the build server's workspace to monitor //depot/ProjectX/MAIN/source (assumes the workspace depot is c:\depot):


<cruisecontrol>
  <project name="ProjectX">
    <sourcecontrol type="p4">
      <view>//depot/ProjectX/MAIN/source...</view>
      <client>build.server</client>
      <applyLabel>true</applyLabel>
      <autoGetSource>true</autoGetSource>
    </sourcecontrol>
    <workingDirectory>C:\depot\ProjectX\MAIN\source</workingDirectory>
    <webURL>http://localhost/ccnet </webURL>
    <artifactDirectory>C:\buildOutput\ProjectX\artifacts</artifactDirectory>
    <modificationDelaySeconds>5</modificationDelaySeconds>
    <triggers>
      <intervalTrigger name="continuous" seconds="10"/>
    </triggers>
    <state type="state" directory="C:\buildOutput\ProjectX\artifacts" />
    <labeller type="iterationlabeller">
      <prefix>1.1</prefix>
      <duration>4</duration>
      <releaseStartDate>2008/5/29</releaseStartDate>
      <separator>.</separator>
    </labeller>
    <tasks>
      <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
        <projectFile>build\ProjectX.build</projectFile>
        <targets>FullBuild</targets>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /verbosity:minimal</buildArgs>
        <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
      </msbuild>
    </tasks>
  </project>
</cruiseControl>
 
This tells CC to connect to Perforce in the build.server workspace, and monitor all files under //depot/ProjectX/MAIN/source. When it finds a change, it will resynchronise (bringing the build server's copy of the source up to date), determine a label for the build, and start the FullBuild target in the MSBuild file.

If the build is successful, the label is applied to all files in the view, so Perforce is stamped with a label for every successful build (this means at any time we can create a branch for a specific build which we know will work). There's no publishing here, but you typically configure CCNet to issue build failure mails to people/lists named in the project.

For multiple projects in the same CCNet config, you can use the same workspace but specify a different view. 
 
MSBuild setup – projectX.build

The build file specifies targets as entry points. Targets can contain other targets, so typically the build process will be split into component parts which are brought together by composite targets. A sample build file split like this is:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="FullBuild">
  <!-- MSBuild extensions required; use installer from Prerequisites-->
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <!-- Properties-->
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <OutputDir>bin\$(Configuration)</OutputDir>
    <ObjOutputDir>obj\$(Configuration)</ObjOutputDir>
    <ProjectDir>..\ProjectX</ProjectDir >
    <ProjectTestDir>..\ProjectX.Test</ProjectTestDir >
    <ProjectFile>$(ProjectDir)\ProjectX.csproj</ProjectFile >
    <TestProjectFile>$(ProjectTestDir)\ProjectX.Test.csproj</TestProjectFile >
    <ExcludeTestCategories>InProgress,LongRunning</ExcludeTestCategories>
    <Version Condition=" '$(CCNetLabel)' == '' ">1.0.0.0</Version>
    <NUnitOutputXmlFile>C:\buildOutput\ProjectX\artifacts\testResults_$(Version).xml</NUnitOutputXmlFile>
  </PropertyGroup>
  <!-- Default entry point, builds & runs all Continuous tests-->
  <Target Name="FullBuild">
    <CallTarget Targets="BuildNoTests"/>
    <CallTarget Targets="UnitTestContinuous"/>
    <CallTarget Targets="Package" />
  </Target>
  <Target Name="BuildNoTests">
    <CallTarget Targets="Build"/>
    <CallTarget Targets="PostBuild"/>
  </Target>
  <ItemGroup>
    <OutputDirectory Include="d1">
      <DirectoryName>
        $(ProjectDir)\$(OutputDir)
      </DirectoryName>
    </OutputDirectory>
    <OutputDirectory Include="d2">
      <DirectoryName>
        $(ProjectDir)\$(ObjOutputDir)</DirectoryName>
    </OutputDirectory>
    <OutputDirectory Include="d3">
      <DirectoryName>$(ProjectTestDir)\$(OutputDir)</DirectoryName>
    </OutputDirectory>
    <OutputDirectory Include="d4">
      <DirectoryName>$(ProjectTestDir)\$(ObjOutputDir)</DirectoryName>
    </OutputDirectory>
  </ItemGroup>
  <ItemGroup>
    <ProjectDirectory Include="p1">
      <DirectoryName>$(ProjectDir)</DirectoryName>
    </ProjectDirectory>
    <ProjectDirectory Include="p2">
      <DirectoryName>$(ProjectTestDir)</DirectoryName>
  </ProjectDirectory>
  </ItemGroup>
  <Target Name="CleanDirectories">
    <Attrib Directories="%(OutputDirectory.DirectoryName)" ReadOnly="false" ContinueOnError="true"/>
    <RemoveDir Directories="%(OutputDirectory.DirectoryName)" ContinueOnError="true"/>
  </Target>
  <Target Name="SetAssemblyVersions">
    <Attrib Files="%(ProjectDirectory.DirectoryName)\Properties\AssemblyInfo.cs" ReadOnly="false"/>
    <AssemblyInfo CodeLanguage="CS" OutputFile="%(ProjectDirectory.DirectoryName)\Properties\AssemblyInfo.cs" AssemblyVersion="$(Version)" AssemblyFileVersion="$(Versiom)" />

  </Target>
  <!--Setup tasks prior to build-->
  <Target Name="PreBuild">
    <Message Importance="high" Text="In target PreBuild"/>
    <!-- Clean the output directories-->
    <CallTarget Targets="CleanDirectories"/>
    <!--Set assembly versions equal to CCNet version-->
    <CallTarget Targets="SetAssemblyVersions"/>
  </Target>
  <!-- Build projects -->
  <Target Name="Build" DependsOnTargets="PreBuild">
    <Message Importance="high" Text="In target Build"/>
    <MSBuild Projects="$(ProjectFile)">
    </MSBuild>
    <MSBuild Projects="$(TestProjectFile)">
    </MSBuild>
  </Target>
  <ItemGroup>
    <ProjectOutput Include="$(ProjectDir)\$(OutputDir)\*.*"/>
  </ItemGroup>
  <ItemGroup>
    <ProjectTestOutput Include="$(ProjectTestDir)\$(OutputDir)\*.*"/>
  </ItemGroup>
  <!--Cleanup tasks after build-->
  <Target Name="PostBuild" DependsOnTargets="Build">
    <Message Importance="high" Text="In target PostBuild"/>
    <Copy SourceFiles="@(ProjectOutput)" DestinationFolder="C:\buildOutput\ProjectX\$(Version)"/>
    <Copy SourceFiles="@(ProjectTestOutput)" DestinationFolder="C:\buildOutput\ProjectX\Test\$(Version)"/>
  </Target>
  <!-- Run all tests with the Continuous category-->
  <Target Name="UnitTestContinuous">
    <Message Importance="high" Text="In target UnitTestContinuous"/>
    <CreateItem Include="SmartRename.Test.Dummy.dll">
      <Output TaskParameter="Include" ItemName="TestAssembly" />
    </CreateItem>
    <Message Importance="high" Text="Assemblies: @(TestAssembly)"/>
    <NUnit ToolPath="C:\Program Files\NUnit 2.4.6\bin" WorkingDirectory="$(ProjectTestDir)\$(OutputDir)" Assemblies="@(TestAssembly)" ExcludeCategory="$(ExcludeTestCategories)" OutputXmlFile="$(NUnitOutputXmlFile)"/>

  </Target>
  <!-- Package a& deployment tasks-->
  <Target Name="Package" DependsOnTargets="Build">
    <Message Importance="high" Text="In target Package"/>
  </Target>
</Project>

 

(note some of the targets are placeholders).


This is more involved and MSBuild is well documented, but the key things to note are:

  • Properties defined in the initial PropertyGroup can be overridden by values passed to the MSBuild exe (with /p:name=value;name2=value2); they are referenced in the script with $(name);
  • ItemGroup allows you to define an array of items that can be operated on (e.g. in CleanDirectories target); the loop is started and entries accessed with %(GroupName.ElementName);
  • Individual items in an ItemGroup can be accessed with @(ItemName);
    DependsOnTargets flag will ensure the necessary targets are run before the executing target, but will not invoke the target if it has already been called;
  • The SetAssemblyVersions target uses a MSBuild Community Task (http://msbuildtasks.tigris.org/) to update the build number in the projects' AssemblyInfo files - this ensures the built assemblies have the same build number as the Perforce source label (available in $(CCNetLabel) property.
Posted on Thursday, May 29, 2008 2:34 PM Perforce , CruiseControl.Net | Back to top


Comments on this post: Sample CruiseControl build using Perforce

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
This was a very well-written blog.Some great information to be absorbed in this post.I have bookmarked this for my friends. Keep blogging.
Left by Bed and Breakfast Lucca on Feb 18, 2010 10:03 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
There is obviously a lot to know about this. I think you made some good points in Features also.
Left by Week end Lucca on Mar 03, 2010 3:56 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I have been searching for Sample CruiseControl build using Perforce. This is really an informative and interesting post for me. I couldn't believe how easy I can understand things when you explain them. Thanks a lot for sharing.
Left by jewelry gifts on Mar 09, 2010 9:10 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
It's a very good blog.And your blog provided us with valuable information to work with.Each & every tips of your post are awesome.Thanks a lot for sharing.Keep blogging.
Left by imergent-44 on Apr 11, 2010 5:58 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
This was a very well-written and enjoyable post to read.I like the way you describe all the things in this post.Some great information to be absorbed in this post.Thanks a lot.Keep blogging.
Left by bandwidth optimization-89 on Apr 26, 2010 7:29 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
We are in the process of developing a production test server which will be accessible through our company's network and we are going to use Perfoce source control server and CC.net. I think this detailed explanation on Perforce setup is really very useful. I am going to keep an eye on any post related to Perforce. Keep updating this.
Left by Multivariate testing on May 25, 2010 7:56 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I couldn't believe how easy I can understand things when you explain them. Really you put very nice code here which are so helpful.There is obviously a lot to know about this.
Left by Hotel Meran on May 28, 2010 9:23 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
This is a great site. Good fresh user interface and very informative blogs.Thanks a lot.Keep blogging.
Left by uterine fibroid embolization59 on Jul 24, 2010 9:03 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Hi, this is one of the best site for the readers and the tips are really very innovative one.Thanks a lot for sharing.Keep blogging.
Left by Cauzione on Aug 03, 2010 5:09 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Cruise Control configuration files are written in XML. This document describes the XML elements and attributes for a valid configuration file.
Left by Management firewall on Nov 02, 2010 5:49 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Good job, Thanks for helping
Left by benjii on Jan 19, 2011 3:49 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
You rock man very good post
Left by send flowers to australia on Mar 09, 2011 7:24 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Kudos to a great post!
Left by Paper writing service on Mar 14, 2011 10:23 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
This is really an informative and interesting post for me. I couldn't believe how easy I can understand things when you explain them. Thanks a lot for sharing.
Left by buy research papers online on Apr 06, 2011 12:35 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
So COOL!!!!
Left by college papers on Apr 08, 2011 2:01 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Excellent stuff from you, man I’ve read your things before and you are just too awesome. I adore what you have got right here. You make it entertaining and you still manage to keep it smart. This is truly a great blog thanks for sharing…
Left by Send mothers day flowers UK on Apr 12, 2011 11:59 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I am absolutely amazed at how terrific the stuff is on this site. I have saved this webpage and I truly intend on visiting the site in the upcoming days. Keep up the excellent work!
Left by flowers Ukraine on Apr 12, 2011 11:59 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
That's completely fascinating site
Left by Essay writers on Apr 14, 2011 12:10 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I am new here. I find a lot of interesting stuff in your weblog especially its discussion. From the number of comments on your articles, I guess I am not the only one having all of the enjoyment here! maintain up the great work.
Left by dermal fillers melbourne on Apr 27, 2011 11:23 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I think this is a great post.
Left by student essay on May 05, 2011 8:24 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Server workspace can be built by using perforce. CC net config can help in channeling data to their server workspace.
Left by on line colleges on May 12, 2011 8:17 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I'll see if this code will work with the settings in my site but I hope it does because I always encounter problems like these every time.
Left by casino på nätet on May 20, 2011 9:43 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
We are a group of independents opening a new scheme in our community, you have done a good job here giving us a whole new way of looking at certain issues, great topic ;-)
London Indian escorts </a
Left by London Escorts on Jun 04, 2011 11:56 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
It is my great pleasure to visit your website and to enjoy your excellent post here. I like that very much. That is very kind of you to do this for us. Thank you very much.
Left by acide hyaluronique on Jun 09, 2011 12:08 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!
Left by rim financing on Jun 14, 2011 8:17 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I will always give a nice thrust look in to you from my bookmark feed. Coffee I don't actually comment and don't like to spend time in typing the comment. But here I have to do this because this deserves a good like.
Left by bank levy on Jun 14, 2011 8:18 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Why don't you use the p4bootstrapper to sync a single path from Perforce before the build begins?
Left by casino on Jul 06, 2011 7:56 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Great Post, the MS Build setup helped me a lot!
Left by Giochi Xbox on Aug 08, 2011 9:21 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Define the P4PORT and P4USER Perforce environment variables, so that the CruiseControl configuration can run on multiple machines that might point to different Perforce Servers.
Left by ted on Sep 09, 2011 9:36 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Thanks for very interesting post.
Left by College papers on Sep 24, 2011 9:01 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
i like post
Left by ali on Oct 11, 2011 9:22 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!
Left by travailler chez soi on Nov 06, 2011 5:07 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...

I want to express my admiration of your writing skill and ability to make viewer, read the whole thing to the end. I'd like to read more of your blogs and to discuss my views with you. I will be your frequent website visitor, that's no doubt.
Left by Johnson City Real Estate on Dec 12, 2011 10:04 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
I am very thankful to the author of this blog because he has given me a very cool thing to read. I have been looking for an article that will satisfy me and I have seen it in this blog..-)
Left by tama on Dec 14, 2011 5:08 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
The moment we've come to stop by right here a little over a working week ago, my brother turned out to be so insistent about creating feedback on Ralph's thought being put up. I however was adamant that we should keep our lips shut for some time and just never make a comment however when he made an effort to make one more comment which gives criticsms about how exactly other folks reacted on his statement, I guess he was dead entirely wrong in it.
Left by Martial Arts Costa Mesa on Feb 13, 2012 12:44 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Understand that certainly nothing can make you genuinely feel that way without having your agreement. It is however normal for men and women to bring below the belt words remember, though , as long as you skin them beforehand, they're not going to go about doing the same. There does exist really a want to stand up by how you feel even it is being faced with a variety of counteraction.
Left by circulon pans on Feb 13, 2012 1:20 PM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Very great post, thanks
Left by travail a domicile on Mar 06, 2012 9:47 AM

# re: Sample CruiseControl build using Perforce
Requesting Gravatar...
Thanks a lot. Want ti try it.
Left by writemy-essay.net on May 30, 2013 10:10 PM

Your comment:
 (will show your gravatar)
 


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net | Join free