Dolly USa
Dolly USa

Reputation: 111

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

I am executing builds using powershell script. I need to pass the process parameters run time based on the commandline arguments passed to the script. I am using 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. 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

Upvotes: 1

Views: 847

Answers (1)

bosco2010
bosco2010

Reputation: 61

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)

Upvotes: 3

Related Questions