如何共享一个标签值之间的多个CC.NET构建? [英] How do I share a label value between multiple CC.NET builds?

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

问题描述

我有两个项目在CC.NET设置:CI构建和每晚构建

I have two projects set up in CC.NET: CI build and nightly build.

他们都执行同样的恶性脚本,但是使用不同的参数。

Both of them execute the same nant script, but with different parameters.

的CCNET标签(目前所产生的的 DefaultLabeler 的)被嵌入到程序集信息作为版本生成部(例如* MajorVersion.MinorVersion.CCNET_Label.SVN_Revision *)

The CCNET label (currently generated by the DefaultLabeler) is embedded into AssemblyInfo as the build part of the version (e.g *MajorVersion.MinorVersion.CCNET_Label.SVN_Revision*).

有关更稳定的版本,我想这两个项目共享相同的CCNET标签值。

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

我已经研究了可作为CC.NET安装的一部分,但无法找到一个我想要做什么的贴标机。

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

我如何共享多个CC.NET之间的标签值建立?

如果有更好的方式来做到这一点,我想知道。

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

编辑:发现了一种方法。见我的回答如下。

推荐答案

我无法找到一个现有的解决方案,做我需要什么,所以我结束了编写自定义CruiseControl.NET贴标机。

I could not find an existing solution that to do what I needed, so I ended up writing a custom CruiseControl.NET labeller.

下面是它是如何做的:


        
  1. 创建一个新的项目。这将通过CC.NET

  2.     
  3. 输出DLL需要匹配* CCNET的名称。\\ *。CruiseControl.plugin *。转到项目
    属性并更改集结号名为* CCNET<这里&GT插入名称; .CruiseControl.plugin *


  4.     
  5. 在您的项目中,添加在CC.NET服务器安装目​​录中找到三集的引用(默认为C:\\ Program Files文件\\ CruiseControl.NET \\服务器):
            

                  
    • NetReflector.dll

    •             
    • ThoughtWorks.CruiseControl.Core.dll

    •             
    • ThoughtWorks.CruiseControl.Remote.dll

    •         
  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

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)
 }
}




    

  • 编译您的项目和DLL复制到CC.NET服务器的安装目录(默认为C:\\ Program Files文件\\ CruiseControl.NET \\服务器)


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

  •     
  • 创建一个文本文件来存储当前的版本号

  •     
  • 要你项目的ccnet.config文件中定义添加新的贴标:



  • Compile your project and copy the DLL to CC.NET server installation directory (default is: C:\Program Files\CruiseControl.NET\server)

  • Restart CC.NET Windows service

  • Create a text file to store the current build number

  • 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>
    
    






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

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