且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有用于 Cruise Control .NET 的 API?

更新时间:2023-01-25 17:38:22

当然有一个 API,因为 Tray 应用程序使用它.我以前从他们的 SVN 存储库下载了代码(注意:按照下面的 URL,它现在托管在 github.com 上)以修复错误(方式上次构建时间"列有效 - 已修复,但在 1.5 版本中有所下降),这可能是一个不错的起点.

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.

存储库 url 是 https://github.com/ccnet/CruiseControl.NET.

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

我刚刚更新了我的本地副本,并通过了一个可能的候选对象是 Remote 项目中的 CruiseServerHttpClient 类.

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.

使用Remote程序集获取每个项目的状态/强制构建

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

  • 从 git 编译源代码
  • 创建一个新的控制台应用程序
  • 添加对 Thoughtworks.CruiseControl.RemoteNetReflector 的引用(两者都将位于 Remote 项目的 \bin 目录中)
  • 将以下代码添加到您的控制台应用程序
  • 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

控制台应用程序代码:

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:

项目名称 - 成功

要强制构建,您需要进行以下调用:

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

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

在幕后,这会导致发出 HTTP 请求,其中包括:

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
内容类型:应用程序/x-www-form-urlencoded
主机:192.168.100.180
内容长度:64
预期:100-继续

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&ser​​verName=local

ForceBuild=true&projectName=PROJECT_NAME&serverName=local