【问题标题】:How do I pass build number from Nant back to Cruise Control如何将内部版本号从 Nant 传递回 Cruise Control
【发布时间】:2008-11-06 11:00:57
【问题描述】:

我有一个 Nant 构建脚本,CruiseControl 使用它来按需构建解决方案。

但是,我们最近才获得 CruiseControl,因此我们的官方内部版本号与 CruiseControl 中列出的不同。

我知道 CruiseControl 会在构建脚本中注入一些属性,以便我可以在脚本 (CCNetLabel) 中访问 CC 内部版本号,但是如何将值传递回 CC 以用作 UI 屏幕上的内部版本号?

例如,CC 表示内部版本号 2

nAnt 脚本每次构建都会增加一个 buildnumber.xml 值,官方的构建号是 123。

我希望 CC UI 显示最后一个成功的内部版本号:123,而不是 2,那么我如何将这个值传递回来?

【问题讨论】:

    标签: version-control build-process cruisecontrol.net nant


    【解决方案1】:

    为此需要自定义构建标签。 Perforce 是我们的源代码控制提供商,我们从中获得了我们的版本号。代码如下:

    /// <summary>
    /// Gets the latest change list number from perforce, for ccnet to consume as a build label.
    /// </summary>
    [ReflectorType( "p4labeller" )]
    public class PerforceLabeller : ILabeller
    {
        //  perforce executable (optional)
        [ReflectorProperty("executable", Required = false)]
        public string P4Executable = "p4.exe";
    
        // perforce port (i.e. myserver:1234)
        [ReflectorProperty("port", Required = false)]
        public string P4Port = String.Empty;
    
        // perforce user
        [ReflectorProperty("user", Required = false)]
        public string P4User = String.Empty;
    
        //  perforce client
        [ReflectorProperty("client", Required = false)]
        public string P4Client = String.Empty;
    
        // perforce view (i.e. //Dev/Code1/...)
        [ReflectorProperty("view", Required = false)]
        public string P4View = String.Empty;
    
        // Returns latest change list
        public string Generate( IIntegrationResult previousLabel )
        {
            return GetLatestChangelist(); 
        }
    
        // Stores latest change list into a label
        public void Run( IIntegrationResult result )
        {
            result.Label = GetLatestChangelist();
        }
    
        // Gets the latest change list
        public string GetLatestChangelist()
        {
            // Build the arguments to pass to p4 to get the latest changelist
            string theArgs = "-p " + P4Port + " -u " + P4User + " -c " + P4Client + " changes -m 1 -s submitted " + P4View;
            Log.Info( string.Format( "Getting latest change from Perforce using --> " + theArgs ) );
    
            // Execute p4
            ProcessResult theProcessResult = new ProcessExecutor().Execute( new ProcessInfo( P4Executable, theArgs ) );
    
            // Extract the changelist # from the result
            Regex theRegex = new Regex( @"\s[0-9]+\s", RegexOptions.IgnoreCase );
            Match theMatch = theRegex.Match( theProcessResult.StandardOutput );
            return theMatch.Value.Trim();
        }
    }
    

    GetLatestChangelist 方法是您可能插入自己的逻辑以与版本控制系统对话的地方。在 Perforce 中,最后一个变更列表的想法是独一无二的。我们的内部版本号以及最终的版本号都基于此。

    一旦你构建了它(到一个程序集 dll 中),你必须将它挂接到 ccnet。您可以将程序集放入服务器目录(ccnet.exe 旁边)。

    接下来您修改您的 ccnet 项目文件以使用此贴标机。我们使用default labeller block 做到了这一点。类似于以下内容:

    <project>
    <labeller type="p4labeller">
        <client>myclient</client>
        <executable>p4.exe</executable>
        <port>myserver:1234</port>
        <user>myuser</user>
        <view>//Code1/...</view>
    </labeller>
    <!-- Other project configuration to go here -->
    </project>
    

    如果您只是想让内部版本号显示在 ccnet 中,那么您就完成了,不需要做任何其他事情。但是,如果您愿意,可以使用已提供的 CCNetLabel 属性访问 NAnt 脚本中的标签。

    希望这会有所帮助。如果您有任何问题,请在 cmets 上发帖告诉我。

    【讨论】:

    • 要编译它,我必须添加对 ThoughtWorks.CruiseControl.Core.dll 和 NetReflector.dll 的引用(都在 CruiseControl.Net 安装文件夹中,然后添加以下内容以导入命名空间:使用 Exortech。 NetReflector;使用 ThoughtWorks.CruiseControl.Core;
    • 我要补充的另一件事是,确保您的程序集 dll 被命名为“ccnet.*.plugin.dll”,其中 * 是您为插件选择的任何名称。
    【解决方案2】:

    您是否尝试使用一些环境变量?我相信CCNet可以处理这些。

    我会对此进行深入研究。

    好吧,我看到了一个解决方案,虽然很脏,但无论如何:

    1- 在您的 CCNET 项目定义中添加 defaultlabeller 部分。它将包含您要显示的内部版本号的模式。

    2- 在 NAnt 中,有一个脚本来更新您的配置文件,插入您想要查看的内部版本号。

    3- 触摸(在 Unix 意义上)ccnet.exe.config 文件以使其重新加载项目配置文件。

    等等。

    【讨论】:

      【解决方案3】:

      我们也遇到过这个问题。我最终写了一个特殊的 CC 标签插件。

      【讨论】:

      • 不,但这真的没那么难。从 net.sourceforge.cruisecontrol.LabelIncrementer 继承,遵循 API 文档,将插件构建到 jar 中,将 jar 添加到 CC config.xml。
      【解决方案4】:

      如果您的内部版本号是连续的,您只需破解巡航控制状态文件,即可为其提供正确的内部版本号。您正在寻找一个名为 [projectName].state 的文件。

      我将 Label 元素更改为正确的数字,并将 LastSuccessfulIntegrationLabel 元素更改为新数字。

      【讨论】:

        【解决方案5】:

        但是,我们最近才得到 CruiseControl 所以我们的官方版本 数字与实际不同 列在 CruiseControl 中。

        有点像 gbanfill 所说的那样,您可以告诉 CC 从什么构建号开始,但无需破解 .ser 文件。您可以使用 JMX 接口设置当前版本号,使其与您的 NAnt 版本号同步。

        您还可以将default label 值设置为您当前的内部版本号,删除 .ser 文件并重新启动 CC。

        但也许最简单的方法是将内部版本号从 NAnt 写入属性文件,然后使用 property file label incrementer 读取该文件。 (一定要设置 setPreBuildIncrementer="true")

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-04-11
          • 2013-01-02
          • 1970-01-01
          • 2013-04-10
          • 2011-02-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多