我找不到答案,但肯定此前已经有人问过了。我正在尝试在各个分支上设置构建,这些分支在工作区映射和其他与分支位置相关的参数方面有所不同,例如解决方案文件。当我们增加主要或次要版本号时,我会分支代码,我计划实现的是当代码分支时,我可以生成具有特定参数的构建定义文件,例如正确的工作区、解决方案文件路径和版本文件路径。
我找不到答案,但肯定此前已经有人问过了。我正在尝试在各个分支上设置构建,这些分支在工作区映射和其他与分支位置相关的参数方面有所不同,例如解决方案文件。当我们增加主要或次要版本号时,我会分支代码,我计划实现的是当代码分支时,我可以生成具有特定参数的构建定义文件,例如正确的工作区、解决方案文件路径和版本文件路径。
string teamProject = "TeamProjectName";
string buildController = "BuildControllerName";
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://<tfs>:<port>/tfs"));
server.EnsureAuthenticated();
IBuildServer buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));
var buildDefinition = buildServer.CreateBuildDefinition(teamProject);
buildDefinition.Name = "TestBuild";
buildDefinition.Description = "description here...";
buildDefinition.ContinuousIntegrationType = ContinuousIntegrationType.Individual;
buildDefinition.Workspace.AddMapping("$/Path/project.sln", "$(SourceDir)", WorkspaceMappingType.Map);
buildDefinition.Workspace.AddMapping("$/OtherPath/", "", WorkspaceMappingType.Cloak);
buildDefinition.BuildController = buildServer.GetBuildController(buildController);
buildDefinition.DefaultDropLocation = @"\\SERVER\Drop\TestBuild";
//Get default template
var defaultTemplate = buildServer.QueryProcessTemplates(teamProject).Where(p => p.TemplateType == ProcessTemplateType.Default).First();
buildDefinition.Process = defaultTemplate;
//Set process parameters
var process = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
//Set BuildSettings properties
BuildSettings settings = new BuildSettings();
settings.ProjectsToBuild = new StringList("$/pathToProject/project.sln");
settings.PlatformConfigurations = new PlatformConfigurationList();
settings.PlatformConfigurations.Add(new PlatformConfiguration("Any CPU", "Debug"));
process.Add("BuildSettings", settings);
buildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
buildDefinition.RetentionPolicyList.Clear();
buildDefinition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Succeeded, 10, DeleteOptions.All);
buildDefinition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Failed, 10, DeleteOptions.All);
buildDefinition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Stopped, 1, DeleteOptions.All);
buildDefinition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.PartiallySucceeded, 10, DeleteOptions.All);
buildDefinition.Save();