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
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> </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.
Scott saad
source share