8
votes

I have managed to do Continuous deployment for my Web project using TFS Msbuild.

I have goggled for few hours but couldn't find a relative link to achieve Continuous Deployment for windows service.

Possible to do CD for windows service using TFS Build Definitions? i.e for every check in below steps should be performed, I am using TFS2010 with Windows Server 2008 R2

1] Stop Service,

2] Copy respective Project folder from (Source) Build server to (Destination Server)'staging server1' or 'staging server2'

3] Start Services (willing to do this step manually)

Any blog,tutorial references to achieve this? My guess is need to use Power shell scripts but not sure.

1
Might help [Excellent James Crowley MSdeploy Windows Service Article here ](jamescrowley.co.uk/2011/09/05/… )Webplanet TFS Consulting

1 Answers

3
votes

Should be ok, you'll need to install an agent on the box you're deploying to. And you'll need to be able to exit the XAML templates (you'll probably want to copy your existing template that does your build and just add the stop/copy/start stuff onto the end of it).

After your CI build, you'll need to edit it (the XAML template) to start and stop the service you can use the "invoke process" activity (you'll probably want to do something like make it generic and pass in the service name as an argument - note you can change the display names etc in the Metadata argument so it appears meaningful in your build definition).

As far as copying stuff across goes, you can do this fairly easily by accessing properties like the drop location.

Should be fairly straight forward - once you get your head round modifying the templates!

Edit:

Sorry for not responding sooner, I'd have to revise my earlier comment, this isn't as straight forward as it seems unless you really know what you want, I have been thinking about this and like skinning cats, there are more than one ways to achieve this... I've rewritten this a few times so I hope the edit's make sense :)

Boils down to the following:

1) Pass into your template the build agent/machine you want to run this on (this can be done as a simple string, or as an AgentReservationSpec - up to you), since it's unlikely to be the machine that you run your actual CI build on. This is done in the Arguments section of the XAML, as noted before, if you want to edit the display name/description you can edit the Metadata Argument. This machine needs a TFS agent installed of course.

2) Run the task on the remote machine, this is done by adding the Agent Scope activity into your template, you will have to use the info from step 1 to get the ReservationSpec (so would be easier if you add the argument as an AgentReservationSpec or you'll need to resolve this in the template)

2.1) Run the stop/uninstall, this is done via dropping in a (two actually) Invoke Process activity, Invoke Process can take arguments and you need to point it to the executable you're executing, so you'll want to use this, one for the NET command (i.e. NET STOP ), and one for InstallUtil.exe.

2.2) Copy the files from your CI to the remote server, you can use the Copy Directory activity for this, it needs a couple of parameters, the main one is the source location, you should be able to drop in a GetBuildDetail activity, give it a name then reference .DropLocation to get this, destination is wherever you like you're installing to.

2.3) Install the new service as step 2.1, you need to use Invoke Process to install the service, then you can use another to start the service up.

I haven't covered everything, but I haven't set this up myself so I'm sure there are a few pitfalls or things I haven't though of. Off the top of my head this makes sense, but maybe someone that knows better can poke a few holes in it :)