Version control 如何将构建号从Nant传递回巡航控制

Version control 如何将构建号从Nant传递回巡航控制,version-control,build-process,cruisecontrol.net,nant,Version Control,Build Process,Cruisecontrol.net,Nant,我有一个Nant构建脚本,CruiseControl使用它按需构建解决方案 然而,我们最近才得到CruiseControl,所以我们的官方版本号与CruiseControl中列出的版本号不同 我知道CruiseControl在构建脚本中注入了一些属性,这样我就可以访问脚本(CCNetLabel)中的CC构建编号,但是我如何将值传递回CC以用作UI屏幕上的构建编号呢 例如,CC表示构建编号2 nAnt脚本在每次生成时都会增加buildnumber.xml值,正式生成号为123 我希望CC UI显示

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

然而,我们最近才得到CruiseControl,所以我们的官方版本号与CruiseControl中列出的版本号不同

我知道CruiseControl在构建脚本中注入了一些属性,这样我就可以访问脚本(CCNetLabel)中的CC构建编号,但是我如何将值传递回CC以用作UI屏幕上的构建编号呢

例如,CC表示构建编号2

nAnt脚本在每次生成时都会增加buildnumber.xml值,正式生成号为123


我希望CC UI显示上次成功生成的版本号:123,而不是2,那么如何将该值传递回备份?

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

我会在这上面挖一点

我看到了一个解决方案,相当肮脏,但无论如何:

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

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

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


瞧,我们也有这个问题。我最后编写了一个特殊的CC标签插件。

为此需要一个定制的构建标签器。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获取最新的更改列表编号,以便ccnet将其用作生成标签。
/// 
[反射器类型(“P4标签机”)]
公共类性能标签:ILabeller
{
//perforce可执行文件(可选)
[反射器属性(“可执行”,必需=false)]
公共字符串P4Executable=“p4.exe”;
//性能端口(即myserver:1234)
[反射器属性(“端口”,必需=false)]
公共字符串P4Port=string.Empty;
//性能用户
[反射器属性(“用户”,必需=false)]
公共字符串P4User=string.Empty;
//性能客户端
[反射器属性(“客户端”,必需=false)]
公共字符串P4Client=string.Empty;
//性能视图(即//Dev/Code1/…)
[反射器属性(“视图”,必需=false)]
公共字符串P4View=string.Empty;
//返回最新的更改列表
生成公共字符串(IIntegrationResult previousLabel)
{
返回GetLatestChangelist();
}
//将最新更改列表存储到标签中
公共作废运行(IIintegrationResult)
{
result.Label=GetLatestChangelist();
}
//获取最新的更改列表
公共字符串GetLatestChangelist()
{
//构建要传递给p4的参数,以获取最新的变更列表
字符串theArgs=“-p”+P4Port+“-u”+P4User+“-c”+P4Client+“更改-m1-s已提交”+P4View;
Log.Info(string.Format(“使用-->”+theArgs从Perforce获取最新更改”);
//执行p4
ProcessResult theProcessResult=newProcessExecutor().Execute(newProcessInfo(P4Executable,theArgs));
//从结果中提取变更列表#
Regex-theRegex=new Regex(@“\s[0-9]+\s”,RegexOptions.IgnoreCase);
Match theMatch=theRegex.Match(processresult.standard输出);
返回match.Value.Trim();
}
}
“GetLatestChangelist”方法是您可能插入自己的逻辑与版本控制系统对话的地方。实际上,最后一个变更列表是唯一的。我们的版本号,以及最终的版本号都基于此

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

接下来,您将修改ccnet项目文件以使用此标签机。这是我们用的。如下所示:

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

我的客户
p4.exe
我的服务器:1234
我的用户
//代码1/。。。
如果您只是想在ccnet中显示版本号,那么您就完成了,不需要做任何其他事情。但是,如果愿意,可以使用已提供的CCNetLabel属性访问NAnt脚本中的标签


希望这对你有所帮助。如果您有任何问题,请在评论中留言。

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

我将标签元素更改为正确的数字,将LastSuccessfulIntegrationLabel更改为新的数字

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

类似于gbanfill所说的,您可以告诉CC从什么构建编号开始,但不需要破解.ser文件。您可以使用JMX接口设置当前版本号,以使其与NAnt版本号同步

您还可以将该值设置为当前版本号,删除.ser文件并重新启动CC


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

否,但这并没有那么难。从net.sourceforge.cruisecontrol.LabelIncrementer继承,遵循API文档,将插件构建到jar中,将jar添加到CC config.xml中。要编译此文件,我必须添加对ThoughtWorks.cruisecontrol.Core.dll和NetReflector.dll的引用(都在CruiseControl.Net安装文件夹中,然后添加以下内容以导入名称空间:使用Exortech.NetReflector;使用ThoughtWorks.CruiseControl.Core;我要添加的另一件事是