Hi,
This has helped me a couple of times, so thought I’d post it. It’s a C# workflow activity that you can incorporate into your TFS 2010 build workflow to queue one build definition from another, i.e. when you’re queueing buddy builds. I’ve used this when I have a single build definition that does a get and compile, and with a second build definition that simply packages the solution ready for deployment.
FYI: The package build definition is very generic, and not tied to a single piece of work, hence splitting it apart from the initial Continuous Integration build definition.
The assumption is that target build definition is in the same TeamProject and TeamCollection as the primary build definition.
using System;
using System.Activities;
using System.Diagnostics;
using System.IO;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Client;
namespace BuildTasks.Activities
{
// Queue a new build from the same Team Project.
// Change this class if you wish to use a different team project.
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class QueueNewBuild : 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; }
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);
var workspace = buildDetail.BuildDefinition.Workspace;
// 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);
buildServer.QueueBuild(buildDef);
}
}
}
Hi Jag,
great post. This is the sort of thing that I am looking at doing for our build environment.
Having recently started dealing with this, could you explain how to use the code that you have pasted? I am guessing somewhere in my xaml file, but I don’t know that yet.
Thanks,
Hi,
It’s probably best to read up on creating workflow activities for your TFS 2010 workflow. It’s probably a little too much to cover in this reply.
This is an excellent blog from Ewald Hofman that will help you..
http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx
Thanks
jP