3

Once you have an IBuildDetail getting the associated changsets used to be accomplished with:

buildDetail.Information.GetNodesByType("AssociatedChangeset")

However, in TFS 2013 with Git that fails to return any changesets.

It's possible I haven't configured TFS correctly, but this is an out of the box installation, not an upgrade, so I'm guessing with the new git support the API has changed.

Any help (or links to useful documentation) would be greatly appreciated.

Jonathan Nixon
  • 4,940
  • 5
  • 39
  • 53
Lee Richardson
  • 8,331
  • 6
  • 42
  • 65

3 Answers3

2

After a lot of fiddling around I finally found the solution. Changeset's have been renamed to Commit's for TFS 2013's git support. Consequently you need to ask for that data when you get build details like this:

var buildDetailSpec = _buildServer.CreateBuildDetailSpec(buildDefinitionUris);
buildDetailSpec.InformationTypes = new[] { "AssociatedCommit" };

Then you perform the query as usual:

var buildQueryResult = _buildServer.QueryBuilds(new [] { buildDetailSpec });
var buildDetail = buildQueryResult[0].Builds;

Then you retrieve the commit, not the changeset, like this:

var commits = buildDetail.Information.GetNodesByType("AssociatedCommit");
var author = commits.First().Fields["Author"];
var comments = commits.First().Fields["Message"];

Note that what was "Comment" has been renamed to "Message" and what was "CheckedInBy" has been renamed to "Author" (or maybe "Committer", they are always the same value for me).

Lee Richardson
  • 8,331
  • 6
  • 42
  • 65
  • Glad you discovered this. The names were not changed capriciously, these reflect Git nomenclature. Author reflects the person who made the code change, committee the person who put them in the repository. These are often, but not always, the same person. – Edward Thomson Jun 05 '14 at 01:58
1

For those interested in getting the current builds list of associated commits (after associate commits since last good build is called) the following code is helpful.

var envVar = context.GetExtension<IEnvironmentVariableExtension>();           
var commits = envVar.GetEnvironmentVariable<IList<AssociatedCommit>>(context, WellKnownEnvironmentVariables.AssociatedCommits);

This is nicer than the marked answer for the current build as you get back the type safe object.

Jason
  • 840
  • 11
  • 23
0

I'm not an expert of tfs, but I found these links, that maybe could be useful:

How to get the History of the sourcecontrol in TFS API?

http://tfsdeployer.codeplex.com/discussions/451215

Community
  • 1
  • 1
clami219
  • 2,958
  • 1
  • 31
  • 45
  • Thanks for the response. At first glance the first link won't get checkins associated with a build, and the second link looks similar to code that used to work with TFS2012, but that also no longer seems to work with TFS2013+Git. But I'll dig in more deeply to the second post and confirm. – Lee Richardson Jun 04 '14 at 15:57