2012-07-17 36 views
1

我正在使用powershell脚本执行构建。我需要根据传递给脚本的命令行参数传递进程参数运行时。我使用TFS 2010传递ProcessParameters运行时(MSBuildArguments)使用Powershell到tfs 2010构建定义

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

$projectName = "test" 
$buildName = "test.Build" 
$tfsServer="xxx" 
$tfsInstance = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$buildService = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]) 
$buildDefinations = $buildService.QueryBuildDefinitions($projName) 

遍历所有这些版本找到我们正在寻找

foreach ($build in $buildDefinations) 
{ 

一个得到这个名字建立实例

$bNameInstance = $build.Name 

    $ClientName = "test1" #default set in the builddefination is "/p:xxx=test" 

    #Get the process parameters. I need to update the default value. How can we process the dictionary and update the value 
    $bMSBuildArguments = $build.ProcessParameters 

    #Once setting is done."/p:xxx=test1" 
    $build.ProcessParameters = $bMSBuildArguments 

    [Void]$buildService.QueueBuild($build)  

} 

我需要帮助在更新使用PowerShell代码的进程参数。我碰到了C#(http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-values.aspx)solution,但不能将其转换成Powershell的

回答

3

答案是在博客中提供的尝试是这样的:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Workflow") 
$request = $build.CreateBuildRequest() 
$process = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($build.ProcessParameters) 

#make changes to your process parameters in $process 
$process.Item("asdf") = "new value" 

$request.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($process) 

$buildService.QueueBuild($request)