I have two projects set up in CruiseControl.NET: CI build and nightly build.
Both of them execute the same NAnt script, but with different parameters.
The Cr
I could not find an existing solution that to do what I needed, so I ended up writing a custom CruiseControl.NET labeller.
Here's how it is done:
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Remote;
// this is the labeller name that will be used in ccnet.config
[ReflectorType("customLabeller")]
public class CustomLabeller : ILabeller
{
[ReflectorProperty("syncronisationFilePath", Required = true)]
public string SyncronisationFilePath { get; set; }
#region ILabeller Members
public string Generate(IIntegrationResult previousResult)
{
if (ShouldIncrementLabel(previousResult))
return IncrementLabel();
if (previousResult.Status == IntegrationStatus.Unknown)
return "0";
return previousResult.Label;
}
public void Run(IIntegrationResult result)
{
result.Label = Generate(result);
}
#endregion
private string IncrementLabel()
{
if(!File.Exists(SyncronisationFilePath))
return "0";
using (FileStream fileStream = File.Open(SyncronisationFilePath,
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.None))
{
// read last build number from file
var bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
string rawBuildNumber = Encoding.ASCII.GetString(bytes);
// parse last build number
int previousBuildNumber = int.Parse(rawBuildNumber);
int newBuildNumber = previousBuildNumber + 1;
// increment build number and write back to file
bytes = Encoding.ASCII.GetBytes(newBuildNumber.ToString());
fileStream.Seek(0, SeekOrigin.Begin);
fileStream.Write(bytes, 0, bytes.Length);
return newBuildNumber.ToString();
}
}
private static bool ShouldIncrementLabel(IIntegrationResult previousResult)
{
return (previousResult.Status == IntegrationStatus.Success ||
previousResult.Status == IntegrationStatus.Unknown)
}
}
C:\Program Files\CruiseControl.NET\server\shared\buildnumber.txt
false