如何在多个CruiseControl.NET版本之间共享标签值? [英] How do I share a label value between multiple CruiseControl.NET builds?

查看:76
本文介绍了如何在多个CruiseControl.NET版本之间共享标签值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CruiseControl.NET中设置了两个项目:CI构建和夜间构建。



它们两个都执行相同的NAnt脚本,但参数不同。 / p>

CruiseControl.NET标签(当前由 DefaultLabeler 生成)被嵌入到AssemblyInfo中,作为该版本的构建部分(例如, MajorVersion.MinorVersion.CCNET_Label.SVN_Revision )。



为了获得更一致的版本控制,我希望两个项目共享相同的CruiseControl.NET标签值。

p>

我已经研究了CruiseControl.NET安装中可用的标签机,但找不到能满足我要求的标签机。



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

如果有更好的方法可以做到这一点,我想知道。



我找到了一种方法。

解决方案

我找不到能满足我需要的现有解决方案,所以我最终写了一个自定义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. 创建一个新的公共类,例如:

     
    使用ThoughtWorks.CruiseControl.Core;
    使用ThoughtWorks.CruiseControl.Remote;

    //这是将在ccnet.config中使用的标签程序名称。
    [ReflectorType( customLabeller)]
    公共类CustomLabeller:ILabeller
    {
    [ReflectorProperty( syncronisationFilePath,Required = true)]
    公共字符串SyncronisationFilePath {get;组; }

    #region ILabeller成员

    公共字符串Generate(IIntegrationResult previousResult)
    {
    if(ShouldIncrementLabel(previousResult))
    return IncrementLabel ();

    如果(previousResult.Status == IntegrationStatus.Unknown)
    返回 0;

    返回previousResult.Label;
    }

    public void Run(IIntegrationResult result)
    {
    result.Label = Generate(result);
    }

    #endregion

    私有字符串IncrementLabel()
    {
    if(!File.Exists(SyncronisationFilePath))
    返回 0;

    使用(FileStream fileStream = File.Open(SyncronisationFilePath,
    FileMode.OpenOrCreate,
    FileAccess.ReadWrite,
    FileShare.None))
    {
    //从文件
    中读取最后一个内部版本号var bytes = new byte [fileStream.Length];
    fileStream.Read(bytes,0,bytes.Length);

    字符串rawBuildNumber = Encoding.ASCII.GetString(bytes);

    //解析最后的内部版本号
    int previousBuildNumber = int.Parse(rawBuildNumber);
    int newBuildNumber = previousBuildNumber + 1;

    //增加内部版本号并写回文件
    bytes = Encoding.ASCII.GetBytes(newBuildNumber.ToString());

    fileStream.Seek(0,SeekOrigin.Begin);
    fileStream.Write(bytes,0,bytes.Length);

    返回newBuildNumber.ToString();
    }
    }

    私有静态布尔ShouldIncrementLabel(IIntegrationResult previousResult)
    {
    return(previousResult.Status == IntegrationStatus.Success ||
    previousResult.Status == IntegrationStatus.Unknown)
    }
    }




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


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



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



  8. 在ccnet.config文件中向项目定义中添加新标签器:

     
    < labeller type = sharedLabeller>
    < syncronisationFilePath> C:\程序文件\CruiseControl.NET\服务器\shared\buildnumber.txt< / syncronisationFilePath>
    < incrementOnFailure> false< / crementOnFailure>
    < / labeller>







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 CruiseControl.NET label (currently generated by the DefaultLabeler) is embedded into AssemblyInfo as the build part of the version (for example, MajorVersion.MinorVersion.CCNET_Label.SVN_Revision).

For more consistent versioning I would like both projects to share the same CruiseControl.NET label value.

I have investigated the labelers that are available as part of the CruiseControl.NET installation, but I could not find one that does what I want.

How do I share a label value between multiple CruiseControl.NET builds?
If there is a better way to do this, I would like to know.

I found a way. See my answer below.

解决方案

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:

  1. Create a new project. This will be used as a plugin library by CC.NET

  2. The name of the output DLL needs to match *ccnet.\*.CruiseControl.plugin*. Go to project properties and change "Assembly name" to *ccnet.<insert name here>.CruiseControl.plugin*

  3. In your project, add references to the three assemblies found in the CC.NET server installation directory (default is: C:\Program Files\CruiseControl.NET\server):
    • NetReflector.dll
    • ThoughtWorks.CruiseControl.Core.dll
    • ThoughtWorks.CruiseControl.Remote.dll

  4. Create a new public class such as this:

    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. Compile your project and copy the DLL to CC.NET server installation directory (default is: C:\Program Files\CruiseControl.NET\server)

  6. Restart CC.NET Windows service

  7. Create a text file to store the current build number

  8. Add the new labeler to you project definition in ccnet.config file:

        <labeller type="sharedLabeller">
            <syncronisationFilePath>C:\Program Files\CruiseControl.NET\server\shared\buildnumber.txt</syncronisationFilePath>
    <incrementOnFailure>false</incrementOnFailure>
        </labeller>
    
    



这篇关于如何在多个CruiseControl.NET版本之间共享标签值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆