Get the CCNetBuildDate in NAnt parallel tasks - cruisecontrol.net

In a cruise control configuration file, I use a set of parallel tasks to call some NAnt targets. I noticed that the CC system parameters (like CCNetBuildDate) are not pushed to the NAnt scripts, while they are pushed when I remove the parallel flag. How can I push the CCNetBuildDate information to my parallel tasks?

When I tested this (1.5) I got 0001-01-01 for CCNetBuildDate.
Until this bug is fixed you could save the correct settings before executing the parallel tasks. As you can not override properties passed on the command line you would have to change their names or use <exec> to call nant directly:
<nant>
<buildFile>SaveCCNetParameters.build</buildFile>
</nant>
<parallel>
<tasks>
<exec>
<executable>$(NAntExePath)</executable>
<buildArgs>-buildfile:Build1.build #CCNetBuildParameters</buildArgs>
</exec>
<exec>
<executable>$(NAntExePath)</executable>
<buildArgs>-buildfile:Build2.build #CCNetBuildParameters</buildArgs>
</exec>
</tasks>
</parallel>
where CCNetBuildParameters is a file looking similar to:
-DCCNetBuildDate=2012-11-10
-DCCNetBuildTime=12:12:12
-DCCNetLabel=123
[...]

Related

Cruise Control parsing "!" character in NAnt file

I have Cruise Control configured with a task to run a NAnt script, which runs an MSTest suite. MSTest allows me to specify test categories so I want to specify "!Integration" (which means "don't run Integration tests"). My Nant script successfully runs when I run it from the command line, but when Cruise runs it, the "!Integration" directive is being garbled -- the Cruise output suggests its inserting a line break after the '!' character. The result is that all my tests run, including integration tests.
Extract from ccnet.config:
<tasks>
<nant>
<executable>C:\nant\bin\nant.exe</executable>
<baseDirectory>C:\MyProject\BuildDirectory</baseDirectory>
<buildFile>MyProject.build</buildFile>
<targetList>
<target>CIServerBuild</target>
</targetList>
</nant>
</tasks>
Extract from MyProject.build:
<target name="CIServerBuild">
:
<call target="RunUnitTests" />
</target>
<target name="RunUnitTests">
<property name="TestCategories" value="!Integration" />
<call target="RunMSTest" failonerror="true"/>
</target>
<target name="RunMSTest">
<call target="BuildListOfTestContainers" failonerror="true"/>
<exec program="${MSTest.exe}"
commandline=" /category:"${TestCategories}" ${TestContainers} /resultsfile:${MSTest.ResultsFile} /nologo "
/>
</target>
Extract from Cruise output:
[exec] Starting 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe ( /category:"!
Integration" /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Data.Tests\bin\Debug\TaxWise.Data.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Domain.Tests\bin\Debug\TaxWise.Domain.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Infrastructure.Tests\bin\Debug\TaxWise.Infrastructure.Tests.dll /resultsfile:.\TestResults\UnitTests.trx /nologo )'
in 'C:\TaxWise\BuildDirectory'
I have tried replacing the '!' character with
'!'
but that made no difference.
Any ideas, anyone?
I suggest splitting the commandline attribute in the exec task into Nant arg elements.
http://nant.sourceforge.net/release/0.85/help/tasks/exec.html
You'll have more flexibility and the readability will increase.
Yes, perhaps it is not caused by CC. Try setting verbose="True" on the <exec> task and check the raw build protocol. Remember what you see on the report page is not the exact output (typically subject to line-wrap and coalescing whitespaces).
Maybe it depends on from where you run the script, a hidden dependency on a build property or different environment variables. You can check the latter using <exec program="cmd.exe" commandline="/c set" />. For the properties you can use the following script:
<script language="C#" prefix="util" verbose="true">
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
foreach (DictionaryEntry entry in new System.Collections.SortedList(project.Properties) )
Console.WriteLine("{0}={1}", entry.Key, entry.Value);
}
]]>
</code>
</script>

How to commit into TortoiseSVN using cruise control config file

hi all,
can any one tell how to commit into
tortoisesvn using cruise control
config file. I am getting an error
"C:*****\Documentation\trunk\dotnet\svn"
is not executable or it may not exist.
here's the config part...
<workingDirectory>C:\*****\Documentation\trunk\dotnet\</workingDirectory>
<category>Individual Solutions</category>
<modificationDelaySeconds>10</modificationDelaySeconds>
<sourcecontrol type="svn">
<trunkUrl>******* svn url *********</trunkUrl>
<username> unname </username>
<password> pwd </password>
<autoGetSource>true</autoGetSource>
</sourcecontrol>
<tasks>
<exec>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
<successExitCodes>0</successExitCodes>
</exec>
<exec>
<executable>iisreset</executable>
<buildArgs>/stop</buildArgs>
</exec>
<exec>
<executable>c:\Program Files\TortoiseSVN\bin\TortoiseProc.exe /command:commit /path:"C:\*****\Documentation\trunk\dotnet\"</executable>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
<successExitCodes>0</successExitCodes>
<description>checkin shared content...</description>
</exec>
<exec>
<executable>iisreset</executable>
<buildArgs>/start</buildArgs>
</exec>
</tasks>
</project>
Thank you all,
There's a few things:
You want to pass the command-line arguments to in the <buildArgs> element, not as part of the <executable> element (like you've done for the "issreset" command, for example).
Why are you checking stuff in after every build? The way you seem to have things set up here, it's just going to go into an infinite loop, building then checking in and building again (because it detected a new check-in). Generally, you don't check build outputs into your repository.

cruisecontrol <buildargs> nant parameter not being passed

I've been trying to use the param in my cruisecontrol build config file to no avail. When checking the cruisecontrol log file, whatever buildargs I try to pass are NOT passed to the call to nAnt.
Here's the nant task:
<nant>
<buildArgs>-D:CCFoo="Unknown" -D:foo="$(foo)"</buildArgs>
<executable>C:\MCR\Trunk\BuildLibrary\NAnt.exe</executable>
<baseDirectory>C:\MCR\Trunk\tek.Build</baseDirectory>
<buildFile>tek.build</buildFile>
<targetList>
<target>cc</target>
</targetList>
<buildTimeoutSeconds>1800</buildTimeoutSeconds>
</nant>
Here's what appears in the logfile for that call to nant:
2010-01-28 08:45:12,815 [TekWebsite:DEBUG] Starting process [C:\MCR\Trunk\BuildLibrary\NAnt.exe] in working directory [C:\MCR\Trunk\tek.Build] with arguments [-nologo -buildfile:tek.build -logger:NAnt.Core.XmlLogger -D:CCNetArtifactDirectory="C:\Program Files (x86)\CruiseControl.NET\server\builds" -D:CCNetBuildCondition=ForceBuild -D:CCNetBuildDate=2010-01-28 -D:CCNetBuildTime=08:45:12 -D:CCNetFailureUsers= -D:CCNetIntegrationStatus=Unknown -D:CCNetLabel=50 -D:CCNetLastIntegrationStatus=Failure -D:CCNetListenerFile="C:\Program Files (x86)\CruiseControl.NET\server\builds\ClarksWebsite_ListenFile.xml" -D:CCNetModifyingUsers= -D:CCNetNumericLabel=50 -D:CCNetProject=TekWebsite -D:CCNetProjectUrl=http://cor-str-mcr08/ccnet/server/local/project/TekWebsite/ViewProjectReport.aspx -D:CCNetRequestSource=Dashboard -D:CCNetWorkingDirectory="C:\Program Files (x86)\CruiseControl.NET\server" cc]
I'm thinking that maybe there's a config setting for cruisecontrol that tells it to ignore buildargs?
I've tried reordering the lines in the nant task, putting buildargs at the top as you see, and a few places in the middle and the bottom. I've tried the different syntaxes that are available for buildargs such as:
-D:CCFoo="Unknown"
-D:CCFoo=Unknown
-DCCFoo=Unknown
I figured this out - the ccnet.config file that's used by the ccnet daemon process won't reload the build config file until either:
a) the process is restarted OR
b) the ccnet.config file is altered or touched in some way.
So I just went into C:\Program Files (x86)\CruiseControl.NET\server.ccnet.config and added a space, saved and now the buildargs are being passed to nant. woohoo!
I had the exact same problem running some bat file but my reason was I has used:
<msbuild>
...
instead of
<exec>
...

How to run a task before updating source files?

I need to run a task in CruiseControl .NET before checking for modification in source control. I mean this task should be the very first thing that CruiseControl will always do. I see
<prebuild> section in cc.config, but it is for running tasks before building a solution, so it is not exactly what I need.
Prebuild DOES fire before the source control get. It comes after the source control block but still fires first. Here's an example I've been using:
<cb:define subversionpath="c:\Program Files\Subversion\bin\svn.exe"
/>
<cb:define name="svn50">
<executable>$(subversionpath)</executable>
<workingDirectory>D:\Projects\B50\Source</workingDirectory>
<trunkUrl>svn://machineName/branches/B_50/Source</trunkUrl>
<autoGetSource>true</autoGetSource>
</cb:define>
<project name="StreamlineCheckBuild" queue="B50">
<triggers>
<intervalTrigger seconds="180" />
</triggers>
<sourcecontrol type="svn">
<cb:svn50/>
<deleteObstructions>true</deleteObstructions>
<forceUpdate>true</forceUpdate>
</sourcecontrol>
<prebuild>
<exec>
<executable>$(subversionpath)</executable>
<buildArgs>cleanup</buildArgs>
<baseDirectory>D:\Projects\B50</baseDirectory>
</exec>
</prebuild>
<tasks>
...
</tasks>
</cruisecontrol>
Use batch file as proxy for the version control utility, eg. svn.bat:
echo do stuff
"c:\program files\Subversion\svn.exe" %*
Use executable atrribute to point to the bach file.

CruiseControl.NET post-build actions

We have CC.NET setup on our ASP.NET app. When we build the project, the ASP.NET app is pre-compiled and copied to a network share, from which a server runs the application.
The server is a bit different from development box'es, and the next server in our staging environment differs even more. The difference is specific config files and so on - so I want to exclude some files - or delete them before the pre-compiled app is copied to a network share.
My config file looks like this:
<project name="Assembly.Web.project">
<triggers>
<intervalTrigger seconds="3600" />
</triggers>
<sourcecontrol type="svn">
<trunkUrl>svn://svn-server/MyApp/Web/Trunk</trunkUrl>
<workingDirectory>C:\build-server\Assembly\Web\TEST-HL</workingDirectory>
<executable>C:\Program Files (x86)\SVN 1.5 bin\svn.exe</executable>
<username>uid</username>
<password>pwd</password>
</sourcecontrol>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe</executable>
<workingDirectory>C:\build-server\Assembly\Web\TEST-HL</workingDirectory>
<projectFile>C:\build-server\Assembly\Web\TEST-HL\Web\Web.sln</projectFile>
<buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
<targets>Build</targets>
<timeout>900</timeout>
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
<publishers>
<buildpublisher>
<sourceDir>C:\build-server\Assembly\Web\PrecompiledWeb</sourceDir>
<publishDir>\\test-web01\Web</publishDir>
<useLabelSubDirectory>false</useLabelSubDirectory>
<alwaysPublish>false</alwaysPublish>
</buildpublisher>
</publishers>
</project>
As you can see, I use a buildPublisher to copy the pre-compiled files to the network share. What I want to do here, is either 1) delete certain files before they are copied or 2) replace those files after they have been copied.
I DO NOT want to have some app running watching specific files for change, and then after that replace the files with other ones. I want something to be either done by CC.NET, or triggered by CC.NET.
Can you launch a .bat file with CC.NET?
I use a NAnt task for all publishing, deploying, cleaning and so on.
Take a look at MSDEPLOY or Web Deployment Projects. There is a question that will provide more detail here
You have to use NAnt for those kind of stuff.
Here is the Task Reference of Nant..
Of course CruiseControl.NET can run a batch file, simply use the exec task. However, an easier answer might just be to have MSBuild do the task for you. It should be simple to add a few steps in the postcompile target.

Resources