简体   繁体   English

使用Powershell将ProcessParameters运行时(MSBuildArguments)传递给tfs 2010构建定义

[英]Pass ProcessParameters runtime (MSBuildArguments) using Powershell to tfs 2010 build definitions

I am executing builds using powershell script. 我正在使用powershell脚本执行构建。 I need to pass the process parameters run time based on the commandline arguments passed to the script. 我需要根据传递给脚本的命令行参数传递进程参数运行时。 I am using TFS 2010. 我正在使用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) 

Loop through all the builds to find the one we are looking for 遍历所有构建以找到我们正在寻找的构建

foreach ($build in $buildDefinations) 
{   

Get the name of this build instance 获取此构建实例的名称

    $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)      

}

I need help in updating the processparameters using the powershell code. 我需要帮助使用powershell代码更新processparameters。 I came across the C# ( http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-values.aspx)solution but not able convert that to Powershell 我遇到了C#( http://blogs.msdn.com/b/jpricket/archive/2010/03/25/tfs2010-queuing-a-build-from-code-with-custom-process-parameter-values。 aspx)解决方案,但无法将其转换为Powershell

The answer is in the blog post provided. 答案在提供的博客文章中。 Try something like this: 尝试这样的事情:

[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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM