version-control - 如何将内部版本号从 Nant 传递回 Cruise Control

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

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

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

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

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

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

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

最佳答案

为此需要自定义构建标签。 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();
    }
}

方法,获取最新更改列表 , 是你可能会插入你自己的逻辑来与你的版本控制系统对话的地方。在 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 中,那么您就完成了,不需要做任何其他事情。但是,如果您愿意,可以使用已提供的 访问 NAnt 脚本中的标签。 CCNetLabel 属性(property)。

希望这会有所帮助。如果您有任何问题,请通过评论告诉我。

关于version-control - 如何将内部版本号从 Nant 传递回 Cruise Control,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/268289/

相关文章:

version-control - 带有版本控制的 FitNesse 测试历史

java - Ant loadproperties 失败(bcel 错误?)

extjs - 如何设置当前为桌面构建的 Sencha ExtJS 项目也适用于移动设备?

cruisecontrol.net - 使用 CC .NET fork 进程

svn - 我们可以告诉 CruiseControl.NET 忽略源代码控制超时错误吗?

c# - 程序集文件版本没有改变?

git - SourceTree Clone - 带有端口的源路径导致不是有效的源路径/URL

magento - 哪些 Magento 网站目录和文件不应该使用 Codeguard 等云备份解决方案进行备份?

c++ - Waf 生成 Visual Studio 项目?

git - Cruise Control .net git 日志无效修订范围