【发布时间】:2021-04-11 09:07:57
【问题描述】:
我正在尝试访问具有“无限期保留”标志(BuildDetail.KeepForever 属性)的本地 TFS 2015 服务器中的每个构建,但 QueryBuilds() 函数需要太长时间才能获取所有构建。
TFS 2015 'Retain Indefinitely' Web GUI Menu Option
我真正需要的是KeepForever 和DropLocation 属性。
我发现使用IBuildDetailSpec 接口可以提高效率,但我找不到可以获取KeepForever 属性的选项。
我当前的代码sn-p:
public void BackupOnlyRetainedBuilds(string TeamProjectName, string DestinationPath)
{
defs[...]
Uri configurationServerUri = new Uri("http://builder:8080/tfs");
TfsTeamProjectCollection server = new TfsTeamProjectCollection(configurationServerUri);
//get builds server
buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));
//set up an array of all build definition from a spcific team project.
IBuildDefinition[] bda = buildServer.QueryBuildDefinitions(TeamProjectName);
//check each build definition.
foreach (var buildDefinition in bda)
{
//set an array of builds history.
IBuildDetail[] bha = buildDefinition.QueryBuilds();
//check each build from build history build details.
foreach (var buildDetails in bha)
{
//check if build is retained.
if (buildDetails.KeepForever == true)
{
string dropLocationPath = buildDetails.DropLocation;
//check if drop folder exists.
if (Directory.Exists(dropLocationPath))
{
//create all of the directories.
foreach (string dirPath in Directory.GetDirectories(dropLocationPath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(dropLocationPath, DestinationPath));
//copy all the files & Replaces any files with the same name.
foreach (string newPath in Directory.GetFiles(dropLocationPath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(dropLocationPath, DestinationPath), true);
}
}
}
}
}
【问题讨论】:
标签: c# tfs build azure-devops azure-pipelines