Arn*_*kas 5 versioning cruisecontrol.net build-automation build ccnet-config
我在CruiseControl.NET中设置了两个项目:CI构建和每晚构建.
它们都执行相同的NAnt脚本,但具有不同的参数.
CruiseControl.NET标签(当前由DefaultLabeler生成)作为版本的构建部分嵌入到AssemblyInfo中(例如,MajorVersion.MinorVersion.CCNET_Label.SVN_Revision).
为了更加一致的版本控制,我希望两个项目共享相同的CruiseControl.NET标签值.
我已经调查了作为CruiseControl.NET安装的一部分提供的贴标机,但我找不到能满足我想要的标签.
如何在多个CruiseControl.NET构建之间共享标签值?
如果有更好的方法,我想知道.
我找到了一个方法.请参阅下面的答案.
我找不到能够做我需要的现有解决方案,所以我最终编写了一个自定义的CruiseControl.NET贴标机.
以下是它的完成方式:
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)
}
}
<labeller type="sharedLabeller">
<syncronisationFilePath>C:\Program Files\CruiseControl.NET\server\shared\buildnumber.txt</syncronisationFilePath>
<incrementOnFailure>false</incrementOnFailure>
</labeller>
| 归档时间: |
|
| 查看次数: |
2247 次 |
| 最近记录: |