How to queue another TFS (2012) Build from a TFS B

2020-04-20 09:25发布

问题:

The product I work on comprises 3/4 seperate (non-dependant) TFS builds.

I would like to create a single TFS build which queues the other 3/4 builds from within the ProcessTemplate AND, critically, pass process parameters to them. This build would wait for them all to complete and return an overall success/failure of the build.

So my questions are:

  • Can this be achieved by any existing 'standard' Workflow activities (my manager has had bad experiences with custom workflow activities)?
  • If not, I am able to 'shell out' to powershell. Can I achieve what I want from within Powershell (accessing the API)?
  • Maybe using TFSBuild.exe? But I can't find a way of passing the custom process parameters I need.

Any assistance or guidance would be appreciated.

UPDATE The following powershell script will execute the build, but I'm still at a loss to be able to pass my custom process parameters :-(

function Get-BuildServer
{
    param($serverName = $(throw 'please specify a TFS server name'))
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName    ("Microsoft.TeamFoundation.Build.Client")
    $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)

    return $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
}

$buildserver = Get-BuildServer "http://tfsserver:8080/tfs/My%20Project%20Collection"
$teamProject = "ESI"
$buildDefinition = "iPrl_BuildMaster"
$definition = $buildserver.GetBuildDefinition($teamProject, $buildDefinition)
$request = $definition.CreateBuildRequest()
$buildserver.QueueBuild($request, "None") 

Now after googling, I have found the following C# code to update the verbosity and, assuming it's the same for my custom process parameters, I need to convert this to work with the above powershell script. Any ideas?

IDictionary<String, Object> paramValues = WorkflowHelpers.DeserializeProcessParameters(processParameters);
paramValues[ProcessParameterMetadata.StandardParameterNames.Verbosity] = buildVerbosity;
return WorkflowHelpers.SerializeProcessParameters(paramValues);