0

TFS 2012 VS 2012 I have large number of Build Definitions that are derived from single template. I also have a Master Build to queue all those builds and pass arguments if I need to do so.

That part was done using TFS Community Extension: QueueBuilds.

Problem: Is there a way to access Build Definitions, loop through them, (can get up to here by myself) and change their ProcessParameters and save them.

Claudius
  • 1,883
  • 2
  • 21
  • 34

1 Answers1

2

You can use the Microsoft.TeamFoundation.Build.Client and related assemblies to update the process parameters via PowerShell or C#. The one tricky part is the parameters are stored in XML so you have to deserialize, make your changes, then serialize again to set them.

This likely won't run without some tweaking but here are some snippets from one of my scripts that will help:

    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Client')
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Workflow')
$projectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSUri)
$buildServer = $projectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])    $buildServer = GetBuildServer -TFSUri $TFSUri
$buildDefinition = $buildServer.GetBuildDefinition($TeamProjectName, $BuildName);
...

  $parameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDefinition.ProcessParameters)
  $msBuildArguments = $parameters.Get_Item("MSBuildArguments")
  $msBuildArguments = "$msBuildArguments /p:ImportParametersFilesOverride=true"
  $parameters.Set_Item("MSBuildArguments", $msBuildArguments)
  $parameters.Add("GetVersion", "c$TFSChangeSetNumber")
  $buildRequest.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($parameters)
chief7
  • 14,263
  • 14
  • 47
  • 80
  • Thank you I will give it a try – Claudius Jan 29 '16 at 14:04
  • GetBuildDefinition($TeamProjectName, $BuildName) Can I pass strings instead of these? I'm going to convert it to to C# so I can run it like custom activity and pass arguments from thats single build to all of them. – Claudius Jan 29 '16 at 14:10
  • Yes, those variables are just set to strings earlier in my script. Welcome to PowerShell! Not an expert yet myself but definitely a tool that is worth learning. – chief7 Jan 29 '16 at 14:15
  • Just to let you know, It worked when I figured out how to save build definitions. – Claudius Jan 29 '16 at 20:26