How to Transfer Nant Build Number Back to Cruise Control

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

However, we only recently received CruiseControl, so our official build number is different from what is indicated in 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 the value back to CC to use as the build number on the user interface screen?

Example: CC says build number 2

The nAnt script increases the buildnumber.xml value for each assembly, and the official assembly number by 123.

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

+6
version-control build-process nant
source share
5 answers

This requires a special shortcut for the assembly. Perforce is our version control provider, and we derive our version number from it. The code is as follows:

/// <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 (ie 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 (ie //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 GetLatestChangelist method is where you are likely to embed your own logic to talk to your version control system. Perforce has the idea of ​​the latest change list, which is unique. Our build numbers and, ultimately, version numbers are based on this.

Once you build this (into the dll assembly), you will have to connect it to ccnet. You can simply delete the assembly in the server directory (next to ccnet.exe).

Then you modify the ccnet project file to use this label. We did this with the default Labeller block . Something like the following:

 <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 just want the build number to appear in ccnet, then everything is ready and you do not need to do anything. However, you can access the label in your NAnt script if you want, using the already provided CCNetLabel property.

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

+7
source share

Have you tried to use some environment variables? I believe CCNet can handle this.

I will work on this a bit.

Well, I see a solution, rather dirty, but anyway:

1- Add the defaultlabeller section to your CCNET project definition. It will contain the assembly number template that you want to display.

2- Inside NAnt, you have a script to update the configuration file by inserting the assembly number that you want to view.

3- Click (in the Unix sense) the ccnet.exe.config file to reload the project configuration files.

et voilΓ .

+1
source share

We also had this problem. In the end, I wrote a special CC marking plugin.

0
source share

If your line numbers are sequential, you can simply hack the cruise control status file so that it gives it the correct build number. You are looking for a file named [projectName] .state.

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

0
source share

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

Regarding the lines of what gbanfill said, you can tell CC which numbers to build from, but there is no need to crack the .ser file. You can use the JMX interface to set the current build number to synchronize it with the NAnt build number.

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

But maybe the simplest thing is to write the assembly number to the properties file from NAnt, and then use the file label label increment to read this file. (Be sure to set setPreBuildIncrementer = "true")

0
source share

All Articles