使用Powershell v4更新TFS 2013构建定义

时间:2015-02-02 18:55:23

标签: powershell tfs tfs2013

我需要在TFS中的几个构建定义上更新构建代理名称。我能够使用我对powershell的有限知识并创建一个让我有点亲近的脚本。问题在于,当保存定义时,所有其他进程参数都被清除(即项目,配置等)。

我觉得我在正确的轨道上,但我只是错过了一两块拼图。这是我的脚本的样子:

$build1 = "build1.tfs.domain.com*"
$build2 = "build2.tfs.domain.com*"
$build3 = "build3.tfs.domain.com*"

add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Common.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll'

$tfsCollectionUrl = "http://tfsserver:8080/tfs/DefaultCollection"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefs = $buildserver.QueryBuildDefinitions("MyTeamProject")

foreach ($def in $buildDefs)
{
$processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($def.ProcessParameters)

Switch ($processParams["AgentSettings"].Name)
{
    "TFSB1*"
    {
        Write-Host "Build definition name:" $build.Name
        Write-Host "Current build agent name:" $processParams["AgentSettings"].Name
        Write-Host "New build agent name:" $build1
        $processParams["AgentSettings"].Name = $build1 
    }
    "TFSB2*"
    {
        Write-Host "Build definition name:" $build.Name
        Write-Host "Current build agent name:" $processParams["AgentSettings"].Name
        Write-Host "New build agent name:" $build2
        $processParams["AgentSettings"].Name = $build2
    }
    "TFSB3*"
    {
        Write-Host "Build definition name:" $build.Name
        Write-Host "Current build agent name:" $processParams["AgentSettings"].Name
        Write-Host "New build agent name:" $build2
        $processParams["AgentSettings"].Name = $build2
    }
}

$def.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($processParams)     
$def.Save()         
}

0 个答案:

没有答案