我已经做了一些调查,并使用TFS默认提供的功能。说实话,它几乎涵盖了我描述的基本场景。
GIT中的默认生成模板包含构建参数调用Checkout override
:
此字段接受变量名,或者干脆修改的ID,你想从建:
这里的好处是,这个设置覆盖(就像名称建议:))默认分支。我的意思是,如果您从主分支创建了一个标签,但在构建定义的“源”选项卡上指定了另一个分支,则无关紧要 - Checkout override
优先。
我会尝试调查高级方案(在我的问题中描述)。我想会有一些自定义代码......会在这里发布更新。
更新2013年12月23日正如预期的那样,为了能够选择要构建的标记,需要一些自定义代码。我最终创建了一个自定义编辑器并将其分配给Checkout override
字段。因此,无法粘贴任何修订ID,只能从列表中选择一个标签 - 但这对我的情况来说很好。
所以,首先你应该为一个字段创建一个自定义编辑器。基本上,创建一个类,从System.Drawing.Design.UITypeEditor
类继承它并重写几个方法。 This walkthrough帮助了很多,以及this book(第18章“定制构建过程”)。
它获取的从特定TFS团队项目的特定的Git回购标签列表中的有用的代码是在这里:
private List<string> GetAvailableTags(IServiceProvider provider)
{
// obtain the current build definition object
var buildDefinition = (IBuildDefinition)provider.GetService(typeof(IBuildDefinition));
// obtain the current source provider for the build definition (Git or TFVC)
var sourceProvider = buildDefinition.GetDefaultSourceProvider();
// obtain the project collection
var teamProjectCollection = buildDefinition.BuildServer.TeamProjectCollection;
// obtain a service object to communicate with Git repo
var gitRepoService = teamProjectCollection.GetService<GitRepositoryService>();
// this will get the partial URL of the Git repo (in a form <teamproject>/<repo>)
var repoUrl = sourceProvider.Fields[BuildSourceProviders.GitProperties.RepositoryName];
string projectName;
string repoName;
// this is the way to parse the partial URL obtained above, into project name and repo name
if (BuildSourceProviders.GitProperties.ParseUniqueRepoName(repoUrl, out projectName, out repoName))
{
// this will get all Git repos of the current team project
var source = gitRepoService.QueryRepositories(projectName);
// this will take the current Git repo we work with
var repo = source.First(x => x.Name.Equals(repoName, StringComparison.OrdinalIgnoreCase));
// this will get all the tags in this Git repo
var tags = gitRepoService.QueryRefs(repo.Id, "tags");
// and finally, the list of pure tag names is returned
return tags.Select(gitRef => gitRef.Name.Substring("refs/tags/".Length)).ToList();
}
return new List<string>();
}
与自定义编辑器中的DLL必须让用户看到它们VS(在我的情况,我只是将程序集放到我的VS安装的Common7\IDE\PrivateAssemblies\
文件夹中)。然后,在该领域的元数据编辑器,你应该指定所需的字段的自定义编辑器:
现在,如果我们编辑构建定义,或排队一个新的版本,我们可以选择从必要的标签下拉菜单:
希望这可以节省一些时间。
你会介意将此片段贡献给ALM Rangers Build Community Extensions吗? http://tfsbuildextensions.codeplex.com/ – jessehouwing
这是一个好主意。你能指出它适合的确切位置吗? –
我已经通知了维护这个的Ranger团队。如果您可以使用“上传补丁”功能上传带有源文件的zip文件,我想我可以设置流程以将它们包括在内...... http://tfsbuildextensions.codeplex.com/SourceControl/latest – jessehouwing