Build server automation tools for continuous integration (CI) are plenteous. Teams bounce from one to another based on pricing and features, and would grab a new brass ring each time they rebuild their CI server if they could. It’s the nature of the beast. Developers like to simplify life and we like shiny new things. So whether our flavor of the year is TFS, Bamboo, Hudson, Jenkins, CC.net, TeamCity, or one of the other dozen or so mainstream tools, we have one common purpose — that is to check source code out of revision control system (RCS) to a somewhat neutral site, and build that code from scratch. Building is followed by testing, the creation of installers, trial deployment, and more testing. I know, sounds familiar.
NCover is about the testing part. NCover profiles the freshly built software as it runs through its automated paces. NCover then serves up a host of .Net code coverage metrics that we responsible types lose sleep over most nights. Well, for now, I’m not so much interested in helping you sleep better. Instead, I want to tell you how to more easily get these metrics in an automated fashion through unattended NCover deployment on your build agents. Those of you with or without build agents, you’ll understand.
Ingredients
- NCover Code Central – at least one, purchase to taste.
- NCover Collector – floating licenses (enough to cover max load).
- Your favorite Windows-based build server.
Code Central
Each NCover Collector must be licensed by and connected to a live Code Central server. Code Central provides both a data repository and a licensing authority for each Collector. Since the build agents in this deployment scenario are ad hoc, the Desktop version of NCover with only a local repository is not a suitable client for this deployment. The best solution is to have a Code Central server and several Collectors with floating licenses which can be deployed to build or testing agents as needed. I won’t go into the Code Central Installation process at this point, but installing and licensing Code Central is a prerequisite to the Collector deployment that follows.
Installing NCover Collector
Once installed, Code Central has copied the installer for Collector to a folder named “downloads” under the location for the Code Central program install. The installer is named in the following pattern: NCover.Collector-4.x.xxxx.xxx.exe.
The simplest way to deploy this exe to a build agent is to add the exe to the same source code repository used for the software source code to be built or tested. This ensures by default that each time the updated source code is deployed to a build agent, the NCover Collector installer is deployed, as well. Once on the local drive of the agent, the NCover installer can be executed in unattended mode using the /i option. This option completes an install without user prompts. The installer must be run in elevated fashion if UAC is active on the agent machine. The elevation allows the installer to create and start the NCover Windows service and register the profiler for coverage.
> ncover.collector.4.x.xxxx.xxx /i TestElevation Installer is elevated ... Destination: C:\Program Files\NCover v4 Collector Begin installation ... Successfully installed NCover as a Windows service. ... Registering: C:\Program Files\NCover v4 Collector\NCover.Coverage.x86.dll Registering: C:\Program Files\NCover v4 Collector\NCover.Launcher.x86.dll Registering: C:\Program Files\NCover v4 Collector\NCover.Coverage.x64.dll Registering: C:\Program Files\NCover v4 Collector\NCover.Launcher.x64.dll ... NCover Collector Service Windows service is currently installed. Service recovery options set for restart. NCover Collector Service Service Start: attempt 1 NCover Service Started by PInvoke
Activating NCover Collector
Central to the notion of unattended deployment is that the software can be licensed and functional without human intervention. NCover 4 now has floating licenses that can be shared across these on-again-off-again agents to better serve economy of scale. See the detailed article on floating licenses posted by Peter earlier.
Licensing for Collector can be accomplished in just a few steps. Don’t forget to release the license when the testing jobs are completed. That process follows this outline:
- Connect to a Code Central Server
- Request a license
- Testing and coverage collection
- Release the license
Connect to a Code Central Server:
> ncover connect --server="http://myCCserver:11233" --username=Some.Joe --password="acaiberries" Usage: ncover.exe connect --server=<Code Central server url> --username=<CC username> --password=<CC password>
Request a license:
> ncover lic-request --floating NCover v4.1.2065.823 x64 (Administrator) Copyright (c) 2007 - 2012 NCover LLC Success! NCover is now licensed to NCover Customer - SOLITON (support@ncover.com). Checked out floating license from Code Central server. Usage: ncover.exe lic-request --floating default is permanent license
Testing and coverage collection
Once the collector has successfully retrieved a license from Code Central, the projects defined on Code Central will be synchronized to the collector. Any collector that connects to Code Central will automatically get a local copy of Code Central’s defined projects. As executions complete on the collector, they are automatically synced back to Code Central.
Release the license
> ncover lic-release NCover v4.1.2065.823 x64 (Administrator) Copyright (c) 2007 - 2012 NCover LLC 2012-10-25T14:02:12 Floating license successfully released.
Releasing the license makes sure that the next agent has is able to secure a license and continue its work, as well. Remember that %ERRORLEVEL% of 0 indicates a successful command. MSBuild tasks handle these command error codes by default.
Quick review of agent commands
ncover.collector.4.x.xxxx.xxx /i ncover connect --server="http://myCCserver:11233" --username=Some.Joe --password="acaiberries" ncover request-lic --floating << do testing/coverage >> ncover release-lic