Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何从命令行获取当前正在运行的TFS构建列表?_Powershell_Tfs_Tfsbuild - Fatal编程技术网

Powershell 如何从命令行获取当前正在运行的TFS构建列表?

Powershell 如何从命令行获取当前正在运行的TFS构建列表?,powershell,tfs,tfsbuild,Powershell,Tfs,Tfsbuild,我正在尝试自动化部署过程,作为其中的一部分,我需要从命令行运行我的发布版本。我可以这样做,就像使用命令一样 \TFSBuild启动http://server-name:8080/tfs/project-集合项目名称生成名称优先级:高/队列 它甚至为排队生成返回一些代码-buildqueued。队列位置:2,队列ID:11057 我不知道的是,如何从powershell命令行获取有关当前正在运行的构建的信息,或者关于正在运行的构建的状态的信息?最终目标是在构建完成后开始发布 我已经有了所有必要的p

我正在尝试自动化部署过程,作为其中的一部分,我需要从命令行运行我的发布版本。我可以这样做,就像使用命令一样

\TFSBuild启动http://server-name:8080/tfs/project-集合项目名称生成名称优先级:高/队列

它甚至为排队生成返回一些代码-
buildqueued。队列位置:2,队列ID:11057

我不知道的是,如何从powershell命令行获取有关当前正在运行的构建的信息,或者关于正在运行的构建的状态的信息?最终目标是在构建完成后开始发布


我已经有了所有必要的powershell脚本,可以根据构建结果创建部署包、压缩它、复制到生产环境并在那里安装。我现在需要做的就是知道我的构建何时成功

此函数将等待具有TFSBuild.exe给定的队列ID的生成:

function Wait-QueuedBuild {
    param(
        $QueueID
    )

    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Client')
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')

    $uri = [URI]"http://server-name:8080/tfs/project-collection"
    $projectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri)
    $buildServer = $projectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
    $spec = $buildServer.CreateBuildQueueSpec('*','*')

    do {
        $build = $buildServer.QueryQueuedBuilds($spec).QueuedBuilds| where {$_.Id -eq $QueueID}
        sleep 1
    } while ($build)
}
您可以获取TFSBuild.exe返回的id,然后调用该函数

$tfsBuild = .\TFSBuild start http://server-name:8080/tfs/project-collection project-name build-name priority:High /queue
Wait-QueuedBuild [regex]::Match($tfsBuild[-1],'Queue ID: (?<id>\d+)').Groups['id'].Value
$tfsBuild=。\tfsBuild开始http://server-name:8080/tfs/project-集合项目名称生成名称优先级:高/队列
Wait QueuedBuild[regex]:Match($tfsBuild[-1],'Queue ID:(?\d+))。组['ID']。值

使用E.Hofman的工作,可以编写一个C#console应用程序,使用TFS SDK并显示是否有任何构建代理当前正在运行,如下所示:

using System;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;

namespace ListAgentStatus
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSServer:8080"));
            var buildServer = teamProjectCollection.GetService<IBuildServer>();

            foreach (IBuildController controller in buildServer.QueryBuildControllers(true))
            {
                foreach (IBuildAgent agent in controller.Agents)
                {
                    Console.WriteLine(agent.Name+" is "+agent.IsReserved);
                }
            }
        }
    }
}
使用系统;
使用Microsoft.TeamFoundation.Build.Client;
使用Microsoft.TeamFoundation.Client;
名称空间ListAgentStatus
{
班级计划
{
静态void Main()
{
TfsTeamProjectCollection teamProjectCollection=TfsTeamProjectCollectionFactory.GetTeamProjectCollection(新Uri(“http://TFSServer:8080"));
var buildServer=teamProjectCollection.GetService();
foreach(buildServer.QueryBuildController中的IBuildController控制器(true))
{
foreach(controller.Agents中的IBILDAgent代理)
{
Console.WriteLine(agent.Name+“是”+agent.IsReserved);
}
}
}
}
}
参数
.IsReserved
是在生成执行期间切换为“True”的参数

很抱歉,我的powershell技能不足以提供上述PS变体。请看一看,bwerks的工作可能会帮助你做到这一点

    # load classes for execution
[Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | Out-Null

# declare working variables
$Uri = New-Object System.Uri "http://example:8080/tfs"

# get reference to projection collection
$ProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($Uri)

# get reference to build server
$BuildServer = $ProjectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

# loop through the build servers
foreach($Controller in $BuildServer.QueryBuildControllers($true))
{
    # loop through agents
    foreach($BuildAgent in $Controller.Agents)
    {
        Write-Host "$($BuildAgent.Name) is $($BuildAgent.IsReserved)"
    }
}