我使用TFS 2012.我需要自定义构建定义的默认模板,以便在构建结束时启动另一个构建定义。
我应该在工作流程中添加哪个元素?
答案 0 :(得分:1)
使用成熟的Community TFS Build Extensions;有一个QueueBuild
活动可供使用。有关自定义研究的指导ALM Rangers' Build Guide。
答案 1 :(得分:0)
我不认为有一个内置的活动来链接一个构建。
我有一个自定义活动,用于在需要时对其他版本进行排队。
代码如下
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Workflow;
using Microsoft.TeamFoundation.Client;
using System;
using System.Activities;
using System.Collections.Generic;
namespace BuildTasks.Activities
{
// Queue a new build from the same Team Project.
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class QueueNewBuildwithParam : CodeActivity
{
// The Team Project that the build definition belongs to.
[RequiredArgument]
public InArgument<IBuildDetail> BuildDetail { get; set; }
// The build definition to queue
[RequiredArgument]
public InArgument<String> BuildDefinition { get; set; }
// The ParamName
[RequiredArgument]
public InArgument<String> ParamName { get; set; }
// The Param Value
[RequiredArgument]
public InArgument<String> ParamValue { get; set; }
protected override void Execute(CodeActivityContext context)
{
// Obtain the runtime value of the input arguments
string buildDefinition = context.GetValue(this.BuildDefinition);
IBuildDetail buildDetail = context.GetValue(this.BuildDetail);
string paramValue = context.GetValue(this.ParamValue);
string paramName = context.GetValue(this.ParamName);
// Obtain the Team Project for the current build definition.
string tfsProject = buildDetail.BuildDefinition.TeamProject;
string configurationServerUri = buildDetail.BuildServer.TeamProjectCollection.Uri.ToString();
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri(configurationServerUri));
server.EnsureAuthenticated();
IBuildServer buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));
IBuildDefinition buildDef = buildServer.GetBuildDefinition(tfsProject, buildDefinition);
IBuildRequest request = buildDef.CreateBuildRequest();
request.ProcessParameters = UpdateBuildDefinitionParam(buildDef.ProcessParameters, paramName, paramValue);
buildServer.QueueBuild(request);
}
private static string UpdateBuildDefinitionParam(string processParameters, string param, string newValue)
{
IDictionary<String, Object> paramValues = WorkflowHelpers.DeserializeProcessParameters(processParameters);
paramValues[param] = newValue;
return WorkflowHelpers.SerializeProcessParameters(paramValues);
}
}
}