Saturday, January 31, 2009

Customizing the code of CCNet : part 3 : Creating a publisher via a plugin

The proces of creating a plugin is already described in the docs, but I'll make a more detailed one here. I'll use the same filePublisher as in my previous post, but this time it will be in the form of a plugin, not as part of the code of CCNet.

Benefits of a plugin :
  • you can easily link to your companies software libs
  • when a new version of CCNet comes out, you do not have to change the code again
Downside of a plugin :
  • Nobody else can extend/improve it
  • if there is a breaking change in CCNet, you will have to make the change to make it work again
Back to the code :
Create a class library, and name the project FilePublisher. You will have the following :

Rename Class1 to FilePublisher, and past in the following code (it's the same as in the previous post:

using System.Collections;
using System.IO;
using System.Xml.Serialization;
using Exortech.NetReflector;

namespace ThoughtWorks.CruiseControl.Core.Publishers
public class FilePublisher : ITask
private string resultFile = "Result.txt";

public string ResultFile
get { return resultFile; }
set { resultFile = value; }

public void Run(IIntegrationResult result)
PublishIt(ResultFile, result);

private void PublishIt(string targetFile, IIntegrationResult result)
StreamWriter Result = new StreamWriter(targetFile, false);
System.Text.StringBuilder Info = new System.Text.StringBuilder();

Info.AppendFormat("Project {0} has status {1}", result.ProjectName, result.Status);
Info.AppendFormat("Modifications :");
foreach (Modification mod in result.Modifications)

Next include references to the following dll's, each can be found in the server folder of the installation folder of CCNet.
° NetReflector
° ThoughtWorks.CruiseControl.Core
° ThoughtWorks.CruiseControl.Remote

In order to let CCNet see this assembly, it must have follow a specific naming : 'ccnet.*.plugin.dll' (where the star represents the name you choose). So our assembly name will be ccnet.FilePublisher.plugin.

Compile and copy the assembly into the folder containing the CruiseControl.NET assemblies. Now you can use this publisher in the same way as in the previous post, by modifying ccnet.config like so :

<filePublisher resultFile="c:\logsresult.txt" />

That was easy ;-)

No comments:

Post a Comment