How can I copy a TFS 2010 Build Definition?

2020-02-26 03:54发布

Is there any way to copy a build definition? I work in a mainline source control methodology which utilizes many different branches that live for very short periods (ie. a few days to a week). I'd really like to copy a build template and just change the solution to build. Is there any way to do this?

7条回答
等我变得足够好
2楼-- · 2020-02-26 04:24

You can write an add-in to do it. Here's the code to copy an existing build definition:

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;
}
查看更多
SAY GOODBYE
3楼-- · 2020-02-26 04:25

I just had a need to copy build definitions, and found Jim's answer above to be helpful. However, being new to the TFS API, I needed help connecting to the server and getting the existing build definition through code. These two links helped fill in the gaps:

http://msdn.microsoft.com/en-us/library/bb286958.aspx

http://geekswithblogs.net/jakob/archive/2010/04/26/creating-a-build-definition-using-the-tfs-2010-api.aspx

查看更多
在下西门庆
4楼-- · 2020-02-26 04:27

You can download the new TFS 2010 power tools. It has the option to clone a build definition.

See http://msmvps.com/blogs/molausson/archive/2010/10/21/clone-a-build-definition.aspx for an example

Note: Be aware that the Clone only works when you did NOT pop out the Build window.

查看更多
forever°为你锁心
5楼-- · 2020-02-26 04:30

You can right click the build definition and select 'clone build definition' to copy the definition file. You can then edit it from there.

查看更多
SAY GOODBYE
6楼-- · 2020-02-26 04:47

From your message it is not clear which template is your build definition using (default, upgrade or lab management). If I understand correctly you would like to easily set up a build definition which builds the same solution but from a different branch.

One thing that you could try instead of copying the definition is to edit it. When the branch dies, rename the build definition (might help with reporting), change the workspace mapping of the build and you should be done.

Thanks, Ladislau

查看更多
ら.Afraid
7楼-- · 2020-02-26 04:50

The following tool (VS Addin) will satisfy your requirement>

Community TFS Build Manager

http://visualstudiogallery.msdn.microsoft.com/16bafc63-0f20-4cc3-8b67-4e25d150102c

查看更多
登录 后发表回答