CruiseControl.NET and PowerShell
It’s been a while – I’m still busy with work, study and a family – not as much time to write as I would like ![]()
I’m currently playing around with PowerShell in my job at the moment. Basically we never have enough time, so I’m trying to figure out how to automate various tasks via PowerShell. And I’ll admit, so far I like it! It is easy to use, has a lot of power and flexibility and there are limitless possibilities for what can be done. But this post isn’t about PowerShell in general – instead I’ve been playing around with building a PowerShell provider for CruiseControl.NET.
“What? But why?” you might say. A while back I built a command-line tool that allows people to interact with a CruiseControl.NET server. But it is very limited and is fairly complex for what it actually does (in terms of the code for it.) As I was playing around with PowerShell I started thinking a lot of the syntax in PowerShell would allow me to build a much better command-line tool, especially when I started seeing the extensibility options for PowerShell.
So I have started putting together a PowerShell provider for CruiseControl.NET. This allows an administrator to connect to a CruiseControl.NET server and administer it. As I’m still playing around with things the code is production quality yet, so use it at your own peril! There is no installer – you will need to grab the code off SourceForge and build it, then copy the contains of the PowerShell\Bin\Debug folder into your modules directory (see help about_modules in PowerShell.)
However if you are interested in seeing what can be done, take a look at the following screen shots:
Here I am:
- Importing the module
- Seeing the new drive that has been mapped
- Getting the child items in the various folders
- Starting all the projects
- And forcing a build for all the projects
I like how I can work with multiple projects at the same time – in my previous tool we would have needed to run the tool once for each project!
I have implemented the cmdlets in the provider to use the pipeline, so we can use a lot of the functionality within PowerShell. For example if we only wanted to get the projects for a certain queue:
This is something that wasn’t even thought of in the command-line tool! And here it is, without any extra work on my behalf ![]()
At the moment I have only implemented four cmdlets:
- Get-Log
- Start-Project
- Stop-Project
- Start-Build
Plus the provider infrastructure (i.e. you can use built-in cmdlets like Get-Item, Get-ChildItem, Set-Location, New-PSDrive, etc.) Currently I have mapped the local server to local:. It is possible to connect to other server using New-PSDrive as long as you know the address for it (this is the same address that CCTray uses.) I have implemented the provider as a hierarchy. The top level is the server itself, with two sub-folders: Queues and Projects.
My next step is to add builds in, but I think this is going to need some changes on the server side to work.
Hopefully this will be helpful to someone ![]()
I’ve looked for this on sf.net but can’t find it. Can you please post a link to the source?
Thanks,
Scott
Hi Scott,
Id didn’t set up a seperate SF project for the source code, I just added it to the main CC.NET project.
Here is a link to the source within the CC.NET project: http://ccnet.svn.sourceforge.net/viewvc/ccnet/trunk/project/PowerShell/
Craig
Nice initiative. Are you sure it is a good idea to use PS Drives to connect to the ccnet servers? Wouldn’t that make it more difficult to manage a lot of CCNet servers? Maybe making a cmdlet to get the projects is better? Get-CCNetProjects localhost | Stop-Project
Thanks for the suggestion Lars. I did initially think about doing it that way, but it sounded like a provider was the better way to go (based on what I had read about the topic.) At the time I was more looking at it for a CC.Net vNext feature, which allows a lot more access to the elements in the configuration, so I might have been slightly biased.
Perhaps I’ll implement both and people can choose which they prefer…
Craig
Also see https://richardspowershellblog.wordpress.com/2007/11/17/powershell-in-sql-2008-provider-vs-cmdlets/ and http://dalelane.co.uk/blog/?p=235 on the subject.