Monitoring long-running NAnt builds under CruiseControl.NET
Say you are using CruiseControl.NET with NAnt to build a large project on your build server and full builds can take a 1/2 hour or more to complete. A common question you may hear is..."how long before the build is done?". This is all purely hypothetical mind-you, it's never happened to me, I can just imagine people asking that :-).
CruiseControl.NET doesn't have a way to let you know if the build just started or is just about to finish. So here is one method you could use. It's very crude and simple, but works surprisingly well.
In brief: You can use NAnt's <echo> task to write certain milestones to a progress text file in your NAnt scripts, then use a little ASP page dropped in the build server's inetpub\wwwroot to display the progress file with an automatic 5-second refresh.
Step 1: Sprinkle echo tasks throughout your build scripts:
---MyProject.build---
<project name="MyProject" default="build">
<property name="progress.log.file" value="buildprogress.txt"/>
<echo message="${datetime::now()}, Start of ${project::get-name()}"
file="${progress.log.file}" append="false"/>
<target name="target1">
<echo message="${datetime::now()}, Start of ${target::get-current-target()}"
file="${progress.log.file}" append="true"/>
:
</target>
<target name="target2">
<echo message="${datetime::now()}, Start of ${target::get-current-target()}"
file="${progress.log.file}" append="true"/>
:
</target>
etc...
<project>
Step 2: Drop an ASP page like the following in your build server's inetpub\wwwroot to view the log as the build is going.
This sample progress.asp file is set up to get the project name from the URL (example: http://buildserver/progress.asp?MyProjectName ) You'll need to fix up the path on this line
fileName = "D:\Build\" & Request.QueryString & "\buildprogress.txt"
to wherever your builds are taking place.
---progress.asp---
<% @Language = "VBScript" %>
<html>
<head>
<meta http-equiv="refresh" content="5">
<style>
body { font-family: arial }
pre {font-size: 8pt }
</style>
</head>
<body>
<table width="100%" border="2" cellpadding="2">
<tr><td bgcolor="darkblue">
<font color="white">
<b> Progress of <%= Request.QueryString %> build</b></font> <font color="white" size="-1">(page will refresh every 5 seconds)</font>
</td></tr>
</table>
<pre>
<%
Dim objFSO, fileName, objTextStream
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
fileName = "D:\Build\" & Request.QueryString & "\buildprogress.txt"
If objFSO.FileExists(fileName) Then
Set objTextStream = objFSO.OpenTextFile(fileName, 1)
Response.Write objTextStream.ReadAll
objTextStream.Close
Set objTextStream = Nothing
Else
Response.Write "Build log " & fileName & " not present."
End If
Set objFSO = Nothing
%>
</pre>
</body>
</html>
Step 3: Then you can add that progress link to your dashboard like this:
---ccnet.config---
<cruisecontrol>
<project name="MyProjectName">
:
<externalLinks>
<externalLink name="Build Progress"
url="http://buildserver/progress.asp?MyProjectName" />
</externalLinks>
</project>
</cruisecontrol>