Wednesday, 29 May 2013

CruiseControl.NET: Trigger Project From its URL

Recently we had a requirement to trigger CCNet projects from a Nant file. I thought since Nant and CruiseControl work so well together it would be a piece of cake. But no, Nant doesn’t have anything to trigger projects.

The CCTray connects to CCNet server using Remoting, in days when WCF looks old there are still applications using Remoting :-). I could, in Nant, write C# code and use the library provided by CruiseControl and do exactly what CCTray does to trigger a project. Well, it’s possible, but there was still something missing.

If I go to a project’s web dashboard and click on the ‘Force Build’ button – then what happens? I thought that since the dashboard is in asp.net, it might well make a Remoting call on the server-side. But to investigate I fired up Fiddler and this is what I saw:

POST http://your-ccnet-server/ccnet/server/local/project/your-ccnet-project/ViewProjectReport.aspx HTTP/1.1
Host: your-ccnet-server
Connection: keep-alive
Content-Length: 16
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://your-ccnet-server
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://your-ccnet-server/ccnet/server/local/project/your-ccnet-project/ViewProjectReport.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

ForceBuild=Force

See the ‘ForceBuild=Force” at the end of the request – it was a happy moment when I saw it.

I formed this URL, browsed to it and the project happily triggered: http://your-build-server/ccnet/server/local/project/your-project-name/ViewProjectReport.aspx?ForceBuild=Force

(The "local" in the URL could vary depending on your dashboard configuration. For that, first try to fetch project report from CCTray and see what is the URL of your Cruise Control.NET project. Based on the URL, modify it to trigger the project)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.