如何在多个CruiseControl.NET构建之间共享标签值?

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构建之间共享标签值?
如果有更好的方法,我想知道.

我找到了一个方法.请参阅下面的答案.

Arn*_*kas 9

我找不到能够做我需要的现有解决方案,所以我最终编写了一个自定义的CruiseControl.NET贴标机.

以下是它的完成方式:

  1. 创建一个新项目.这将被CC.NET用作插件库

  2. 输出DLL的名称需要匹配*ccnet.\*.CruiseControl.plugin*.转到项目属性并将"程序集名称"更改为*ccnet.<在此处插入名称> .CruiseControl.plugin*

  3. 在项目中,添加对CC.NET服务器安装目录中找到的三个程序集的引用(默认为:C:\ Program Files\CruiseControl.NET\server):
    • NetReflector.dll
    • ThoughtWorks.CruiseControl.Core.dll
    • ThoughtWorks.CruiseControl.Remote.dll

  4. 创建一个新的公共类,如下所示:
    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)
     }
    }
    


  5. 编译项目并将DLL复制到CC.NET服务器安装目录(默认为:C:\ Program Files\CruiseControl.NET\server)

  6. 重新启动CC.NET Windows服务

  7. 创建一个文本文件来存储当前的内部版本号

  8. 将新的贴标机添加到ccnet.config文件中的项目定义中:
        <labeller type="sharedLabeller">
            <syncronisationFilePath>C:\Program Files\CruiseControl.NET\server\shared\buildnumber.txt</syncronisationFilePath>
    <incrementOnFailure>false</incrementOnFailure>
        </labeller>