Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <pre><code>/// &lt;summary&gt; /// Gets the latest change list number from perforce, for ccnet to consume as a build label. /// &lt;/summary&gt; [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 --&gt; " + 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(); } } </code></pre> <p>The method, <strong>GetLatestChangelist</strong>, 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. </p> <p>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). </p> <p>Next you modify your ccnet project file to utilize this labeller. We did this with the <a href="http://confluence.public.thoughtworks.org/display/CCNET/Default+Labeller" rel="nofollow noreferrer">default labeller block</a>. Something like the following:</p> <pre><code>&lt;project&gt; &lt;labeller type="p4labeller"&gt; &lt;client&gt;myclient&lt;/client&gt; &lt;executable&gt;p4.exe&lt;/executable&gt; &lt;port&gt;myserver:1234&lt;/port&gt; &lt;user&gt;myuser&lt;/user&gt; &lt;view&gt;//Code1/...&lt;/view&gt; &lt;/labeller&gt; &lt;!-- Other project configuration to go here --&gt; &lt;/project&gt; </code></pre> <p>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 <strong>CCNetLabel</strong> property. </p> <p>Hope this helps some. Let me know if you have any questions by posting to the comments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload