如何将内部编号从Nant传递回Cruise Control

时间:2021-11-24 07:21:42

I have a Nant build script which CruiseControl uses to build a solution on-demand.

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

However, we only recently got CruiseControl so our official build number is different from what is listed in CruiseControl.

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

I know CruiseControl injects some properties into build scripts so that I can access the CC build number in the script (CCNetLabel) but how do I pass a value back to CC to use as the build number on the UI screen?

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

Example, CC says build number 2

例如,CC表示编号为2

nAnt script increments a buildnumber.xml value every build, and the official build number is on 123.

nAnt脚本在每次构建时增加buildnumber.xml值,官方内部版本号在123上。

I want the CC UI to show last successful build number: 123, not 2, so how do I pass that value back up?

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

5 个解决方案

#1


7  

A custom build labeler is required for this. Perforce is our source control provider and we derive our version number from it. The code is as follows:

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

The method, GetLatestChangelist, is where you would probably insert your own logic to talk to your version control system. In Perforce there is the idea of the last changelist which is unique. Our build numbers, and ultimately version numbers are based off of that.

方法GetLatestChangelist是您可能插入自己的逻辑以与版本控制系统通信的地方。在Perforce中,最后一个变更列表的概念是独一无二的。我们的构建号,最终版本号基于此。

Once you build this (into an assembly dll), you'll have to hook it into ccnet. You can just drop the assembly into the server directory (next to ccnet.exe).

一旦你构建了这个(进入程序集dll),你就必须将它挂钩到ccnet。您只需将程序集放入服务器目录(ccnet.exe旁边)即可。

Next you modify your ccnet project file to utilize this labeller. We did this with the default labeller block. Something like the following:

接下来,修改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>

If you're just wanting the build number to show up in ccnet then you're done and don't really need to do anything else. However, you can access the label in your NAnt script if you wish by using the already provided CCNetLabel property.

如果你只是想让内部版本号出现在ccnet中那么你已经完成了,并且真的不需要做任何其他事情。但是,如果您希望使用已提供的CCNetLabel属性,则可以访问NAnt脚本中的标签。

Hope this helps some. Let me know if you have any questions by posting to the comments.

希望这会有所帮助。如果您对评论有任何疑问,请通知我。

#2


1  

Did you try to use some environment variables? I believe CCNet can handle these.

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

I'll dig a bit on this.

我会对此有所了解。

Well I see a solution, quite dirty, but anyhow:

好吧,我看到一个解决方案,非常脏,但无论如何:

1- Add a defaultlabeller section in your CCNET project definition. It will contains the pattern of the build number you want to display.

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

2- Within NAnt, have a script to update your configuration file, inserting the build number you want to see.

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

3- Touch (in the Unix sense) the ccnet.exe.config file so as to make it re-load the projects configuration files.

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

et voilà.

#3


0  

We had this problem as well. I ended up writing a special CC labelling plugin.

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

#4


0  

If your build numbers are sequential, you can just hack the cruise control state file to give it the correct build number to start with. Your looking for a file called [projectName].state.

如果您的构建号是顺序的,您可以破解巡航控制状态文件,以便为其提供正确的构建号。您正在寻找名为[projectName] .state的文件。

I changed the Label element to the correct number and the LastSuccessfulIntegrationLabel to be the new number.

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

#5


0  

However, we only recently got CruiseControl so our official build number is different from what is listed in CruiseControl.

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

Sort of along the lines of what gbanfill said, you can tell CC what build numbers to start from, but there's no need to hack the .ser file. You can use the JMX interface to set the current build number to get it in sync with your NAnt build number.

按照gbanfill所说的排序,你可以告诉CC从哪个构建数开始,但是没有必要破解.ser文件。您可以使用JMX界面设置当前内部版本号,以使其与您的NAnt内部版本号同步。

You can also set the default label value to to your current build number, delete the .ser file and restart CC.

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

But maybe the easiest thing is to write the build number into a property file from NAnt and then use the property file label incrementer to read that file. (Be sure to to set setPreBuildIncrementer="true")

但也许最简单的方法是将构建号写入NAnt的属性文件中,然后使用属性文件标签增量器来读取该文件。 (一定要设置setPreBuildIncrementer =“true”)

#1


7  

A custom build labeler is required for this. Perforce is our source control provider and we derive our version number from it. The code is as follows:

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

The method, GetLatestChangelist, is where you would probably insert your own logic to talk to your version control system. In Perforce there is the idea of the last changelist which is unique. Our build numbers, and ultimately version numbers are based off of that.

方法GetLatestChangelist是您可能插入自己的逻辑以与版本控制系统通信的地方。在Perforce中,最后一个变更列表的概念是独一无二的。我们的构建号,最终版本号基于此。

Once you build this (into an assembly dll), you'll have to hook it into ccnet. You can just drop the assembly into the server directory (next to ccnet.exe).

一旦你构建了这个(进入程序集dll),你就必须将它挂钩到ccnet。您只需将程序集放入服务器目录(ccnet.exe旁边)即可。

Next you modify your ccnet project file to utilize this labeller. We did this with the default labeller block. Something like the following:

接下来,修改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>

If you're just wanting the build number to show up in ccnet then you're done and don't really need to do anything else. However, you can access the label in your NAnt script if you wish by using the already provided CCNetLabel property.

如果你只是想让内部版本号出现在ccnet中那么你已经完成了,并且真的不需要做任何其他事情。但是,如果您希望使用已提供的CCNetLabel属性,则可以访问NAnt脚本中的标签。

Hope this helps some. Let me know if you have any questions by posting to the comments.

希望这会有所帮助。如果您对评论有任何疑问,请通知我。

#2


1  

Did you try to use some environment variables? I believe CCNet can handle these.

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

I'll dig a bit on this.

我会对此有所了解。

Well I see a solution, quite dirty, but anyhow:

好吧,我看到一个解决方案,非常脏,但无论如何:

1- Add a defaultlabeller section in your CCNET project definition. It will contains the pattern of the build number you want to display.

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

2- Within NAnt, have a script to update your configuration file, inserting the build number you want to see.

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

3- Touch (in the Unix sense) the ccnet.exe.config file so as to make it re-load the projects configuration files.

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

et voilà.

#3


0  

We had this problem as well. I ended up writing a special CC labelling plugin.

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

#4


0  

If your build numbers are sequential, you can just hack the cruise control state file to give it the correct build number to start with. Your looking for a file called [projectName].state.

如果您的构建号是顺序的,您可以破解巡航控制状态文件,以便为其提供正确的构建号。您正在寻找名为[projectName] .state的文件。

I changed the Label element to the correct number and the LastSuccessfulIntegrationLabel to be the new number.

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

#5


0  

However, we only recently got CruiseControl so our official build number is different from what is listed in CruiseControl.

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

Sort of along the lines of what gbanfill said, you can tell CC what build numbers to start from, but there's no need to hack the .ser file. You can use the JMX interface to set the current build number to get it in sync with your NAnt build number.

按照gbanfill所说的排序,你可以告诉CC从哪个构建数开始,但是没有必要破解.ser文件。您可以使用JMX界面设置当前内部版本号,以使其与您的NAnt内部版本号同步。

You can also set the default label value to to your current build number, delete the .ser file and restart CC.

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

But maybe the easiest thing is to write the build number into a property file from NAnt and then use the property file label incrementer to read that file. (Be sure to to set setPreBuildIncrementer="true")

但也许最简单的方法是将构建号写入NAnt的属性文件中,然后使用属性文件标签增量器来读取该文件。 (一定要设置setPreBuildIncrementer =“true”)