How to retrieve changesets associated with a build in TFS 2013 with Git?

牧云@^-^@ 提交于 2019-12-01 21:06:46

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).

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.

clami219

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!