有没有办法复制构建定义?我使用主线源控制方法,该方法利用许多不同的分支,这些分支可以存在很短的时间(即几天到一周)。我真的很想复制一个构建模板,只需要改变构建的解决方案。有没有办法做到这一点?
答案 0 :(得分:36)
您可以下载新的TFS 2010 power tools。它可以选择克隆构建定义。
请参阅http://msmvps.com/blogs/molausson/archive/2010/10/21/clone-a-build-definition.aspx以获取示例
注意:请注意,只有在您没有弹出“构建”窗口时,“克隆”才有效。
答案 1 :(得分:12)
您可以编写加载项来执行此操作。这是复制现有构建定义的代码:
static IBuildDefinition CloneBuildDefinition(IBuildDefinition buildDefinition)
{
var buildDefinitionClone = buildDefinition.BuildServer.CreateBuildDefinition(
buildDefinition.TeamProject);
buildDefinitionClone.BuildController = buildDefinition.BuildController;
buildDefinitionClone.ContinuousIntegrationType = buildDefinition.ContinuousIntegrationType;
buildDefinitionClone.ContinuousIntegrationQuietPeriod = buildDefinition.ContinuousIntegrationQuietPeriod;
buildDefinitionClone.DefaultDropLocation = buildDefinition.DefaultDropLocation;
buildDefinitionClone.Description = buildDefinition.Description;
buildDefinitionClone.Enabled = buildDefinition.Enabled;
buildDefinitionClone.Name = String.Format("Copy of {0}", buildDefinition.Name);
buildDefinitionClone.Process = buildDefinition.Process;
buildDefinitionClone.ProcessParameters = buildDefinition.ProcessParameters;
foreach (var schedule in buildDefinition.Schedules)
{
var newSchedule = buildDefinitionClone.AddSchedule();
newSchedule.DaysToBuild = schedule.DaysToBuild;
newSchedule.StartTime = schedule.StartTime;
newSchedule.TimeZone = schedule.TimeZone;
}
foreach (var mapping in buildDefinition.Workspace.Mappings)
{
buildDefinitionClone.Workspace.AddMapping(
mapping.ServerItem, mapping.LocalItem, mapping.MappingType, mapping.Depth);
}
buildDefinitionClone.RetentionPolicyList.Clear();
foreach (var policy in buildDefinition.RetentionPolicyList)
{
buildDefinitionClone.AddRetentionPolicy(
policy.BuildReason, policy.BuildStatus, policy.NumberToKeep, policy.DeleteOptions);
}
return buildDefinitionClone;
}
答案 2 :(得分:2)
以下工具(VS Addin)将满足您的要求>
社区TFS构建经理
http://visualstudiogallery.msdn.microsoft.com/16bafc63-0f20-4cc3-8b67-4e25d150102c
答案 3 :(得分:1)
我只需要复制构建定义,并且发现Jim的上述答案对您有所帮助。但是,作为TFS API的新手,我需要帮助连接到服务器并通过代码获取现有的构建定义。这两个链接有助于填补空白:
答案 4 :(得分:1)
您可以右键单击构建定义,然后选择“克隆构建定义”以复制定义文件。然后,您可以从那里进行编辑。
答案 5 :(得分:1)
如果要将Build定义从一个Team Project移动到其他Team项目,可以使用以下解决方案。
public void MoveBuild(string fromTeamProject, string toTeamProject, string buildName, string newBuildName)
{
var _server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new
Uri("http://Mytfs:8080/defaultcollection"));
IBuildServer _buildServer = _server.GetService<IBuildServer>();
var buildDetails = _buildServer.QueryBuildDefinitions(fromTeamProject);
foreach (var fromBuild in buildDetails)
{
if (fromBuild.Name != buildName) continue;
var newBuildDefinition = _buildServer.CreateBuildDefinition(toTeamProject);
newBuildDefinition.Name = !string.IsNullOrEmpty(newBuildName) ? newBuildName : fromBuild.Name;
newBuildDefinition.BuildController = fromBuild.BuildController;
// This finds the template to use
foreach (var mapping in fromBuild.Workspace.Mappings)
{
newBuildDefinition.Workspace.AddMapping(
mapping.ServerItem, mapping.LocalItem, mapping.MappingType, mapping.Depth);
}
newBuildDefinition.DefaultDropLocation = fromBuild.DefaultDropLocation;
newBuildDefinition.Description = fromBuild.Description;
// buildDefinition.Workspace.AddMapping(build.Workspace.);
newBuildDefinition.Process = _buildServer.QueryProcessTemplates(fromBuild)[2];
newBuildDefinition.ProcessParameters = fromBuild.ProcessParameters;
newBuildDefinition.Enabled = false;
newBuildDefinition.Save();
}//end of for each loop
}
答案 6 :(得分:0)
根据您的消息,不清楚您的构建定义使用哪个模板(默认,升级或实验室管理)。如果我理解正确,您希望轻松设置构建定义,该构建定义构建相同的解决方案,但来自不同的分支。
您可以尝试而不是复制定义的一件事是编辑它。当分支死亡时,重命名构建定义(可能有助于报告),更改构建的工作区映射,您应该完成。
谢谢,Ladislau