Is there an API for Cruise Control .NET? [closed]
Asked Answered
M

3

29

Is there an API I can use with Cruise Control .NET (ccnet) to query the server, for example to get the status of various builds?

I have noticed that there are a few options in the ccnet tray application for connecting but I cannot find any documentation of the service API or examples of how to consume it.

Milan answered 12/8, 2010 at 12:0 Comment(0)
M
34

There's certainly an API as the Tray application uses it. I've downloaded the code from their SVN repository previously (NOTE: as per the URL below, it's now hosted on github.com) to fix a bug (the way the "Last Build Time" column works - which was fixed, but regressed in the 1.5 release), and that'd probably be a good place to start.

The repository url is https://github.com/ccnet/CruiseControl.NET.

I've just updated my local copy and had a mooch through and a likely candidate for what you want is the CruiseServerHttpClient class in the Remote project.

Using the Remote assembly to obtain the status of each project / force a build

  • Compile the source from git
  • Create a new console application
  • Add a reference to Thoughtworks.CruiseControl.Remote and NetReflector (both will be in the \bin directory for the Remote project)
  • Add the following code to your console application

Console application code:

using System;
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Remote;
using ThoughtWorks.CruiseControl.Remote.Messages;

namespace CruiseControlInterface
{
    class Program
    {
        static void Main(string[] args)
        {
            var ipAddressOrHostNameOfCCServer = ""; // Complete this value
            var client = new CruiseServerHttpClient(
                string.Format("http://{0}/ccnet/",ipAddressOrHostNameOfCCServer));

            foreach (var projectStatus in client.GetProjectStatus())
            {
                Console.WriteLine("{0} - {1}", projectStatus.Name, projectStatus.BuildStatus);
            }
        }
    }
}

For each project you'll get output similar to:

ProjectName - Success

To force a build, you'd make the following call:

client.Request("PROJECT_NAME", new IntegrationRequest(BuildCondition.ForceBuild, "YOUR_MACHINE_NAME", "YOUR_USER_NAME"));

Under the hood this results in a HTTP request being made that consists of:

POST http://CC_SERVER_NAME/ccnet/ViewFarmReport.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: 192.168.100.180
Content-Length: 64
Expect: 100-continue

ForceBuild=true&projectName=PROJECT_NAME&serverName=local

Melville answered 12/8, 2010 at 20:29 Comment(5)
Spot on answer that cheeers!! :-)Milan
The assemblies Thoughtworks.CruiseControl.Remote.dll and NetReflector.dll are also located in the cctray program files directory.Beverleebeverley
In your example Forcing a build requires machine name and user. Is this just for logging since it is not sent down in the post?Methinks
@Luke - no idea, I suspect that as it isn't sent over the wire it's either entirely redundant or used, as you suggest, for logging only.Melville
I can print out the list of projects, but trying to force a build does nothing. Was anyone able to get that to work?Spelaean
C
10

Add the Nuget package CruiseControl.Net to your project. http://www.nuget.org/packages/CruiseControl.Net/

This will add the references to ThoughtWorks.CruiseControl.Core, ThoughtWorks.CruiseControl.Remote and NetReflector to your project(s) and give you an easy way to keep it up to date.

Colcothar answered 6/8, 2013 at 13:19 Comment(0)
C
8

You can also query directly over HTTP, by loading the page http://CC_SERVER_NAME/ccnet/XmlStatusReport.aspx. This will return an XML document giving the statuses of all your build projects, as is rendered on the page http://CC_SERVER_NAME/ccnet/ViewFarmReport.aspx.

It would be nice if you could drill down into that to get at a build project's history - maybe you can, I haven't tried!

Coacher answered 16/8, 2012 at 0:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.