代码之家  ›  专栏  ›  技术社区  ›  Sameer Singh

使用PowerShell创建CCNet服务器上所有项目的列表

  •  2
  • Sameer Singh  · 技术社区  · 14 年前

    有办法吗?

    我的第一直觉是使用PowerShell(v2.0),但我不确定如何开始编写一个符合我要求的脚本。我应该使用PowerShell还是其他方法?其他的方法是什么?

    4 回复  |  直到 14 年前
        1
  •  1
  •   Jaykul    14 年前

    如果您可以访问ccnet.config文件,您可以:

    ([xml](Get-Content ccnet.config)).cruisecontrol.project | Select name, artifactDirectory # or whatever
    
        2
  •  4
  •   Alex    14 年前

    我将使用Thoughtworks.CruiseControl.Remote.dll并将其加载到powershell中

    创建 ICruiseManagerFactory managerFactory;

    然后,您可以遍历您拥有的服务器列表,并为服务器创建Uri,如:

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

    然后使用以下命令从该服务器获取项目和状态列表:

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

    然后遍历列表:

            foreach (ProjectStatus projectStatus in currentStatuses)
            {
                string name = projectStatus.Name;
                string status = projectStatus.Status;
      }
    
        3
  •  2
  •   Preet Sangha    14 年前

    起点 here here

        4
  •  0
  •   Sameer Singh    12 年前

    总而言之,以下是我在特定生成服务器上创建项目列表的脚本:

    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
    }
    

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

    我希望这能有帮助!