开发者

Use PowerShell to Create a List of All Projects on a CCNet Server

开发者 https://www.devze.com 2023-01-24 07:23 出处:网络
I have been tasked with auditing 开发者_运维百科build servers using CruiseControl.NET. There are quite a few of them, and I was wondering if there was a way to programmatically / automagically compile

I have been tasked with auditing 开发者_运维百科build servers using CruiseControl.NET. There are quite a few of them, and I was wondering if there was a way to programmatically / automagically compile a list of the projects on each of them.

Is there a way to do this?

My first instinct is to use PowerShell (v2.0), but I am not sure how to begin writing a script that does what I require. Should I be using PowerShell, or some other method? What would those other methods be?


I would use the Thoughtworks.CruiseControl.Remote.dll and load it into powershell

Create ICruiseManagerFactory managerFactory;

and then you could iterate through a list of servers you have and Create the Uri for the server like:

 ServerUri = @"tcp://" + Server + ":" + Port + @"/CruiseManager.rem"

then get the list of Projects and statuses from that server using:

 ProjectStatus[] currentStatuses = managerFactory.GetCruiseManager(ServerUri).GetProjectStatus();

then iterate through the list:

        foreach (ProjectStatus projectStatus in currentStatuses)
        {
            string name = projectStatus.Name;
            string status = projectStatus.Status;
  }


Powershell can read xml files really easily. You should use this to interrogate the CC.NET builds.

Start here and here


If you can access the ccnet.config files, you can just:

([xml](Get-Content ccnet.config)).cruisecontrol.project | Select name, artifactDirectory # or whatever


Thanks to everyone for their answers. :-) One thing I failed to mention is that all of the build servers have the same installation structure for CruiseControl.NET on them, and the installation directory is directly accessible through a folder share.

Putting it all together, here is my script for creating a list of projects on a particular build server:

function Get-Projects
{
  param([string]$BuildServer = $(Throw "You must specify the name of the build server containing the projects you want to list"))
  $BuildServer = $BuildServer.ToUpper()

  $ConfigFilePath = [string]"\\$BuildServer\CruiseControl.NET\server\ccnet.config"
  $ValidPath = Test-Path -Path "$ConfigFilePath"
  if (!$ValidPath)
  {
    $InvalidPathErrorMessage = [string]"Path $ConfigFilePath does not exist!"
    Write-Host $InvalidPathErrorMessage
    $InvalidPathErrorMessage
    return
  }

  $ConfigXml = [xml](Get-Content $ConfigFilePath)
  $Projects = @($ConfigXml.SelectNodes("cruisecontrol/project"))

  if (!$Projects)
  {
    $ErrorMessage = [string]"No projects on $BuildServer!"
    Write-Host $ErrorMessage
    $ErrorMessage
    return
  }

  $Projects
}

Then, assuming this script is accessible within your PowerShell session, you can simply select the data you want, as Jaykul suggested:

Get-Projects <BuildServer> | Select-Object name, queue, category | Sort-Object category

I hope this is found to be helpful!

0

精彩评论

暂无评论...
验证码 换一张
取 消