public static void BuildDefinition(string collection, string teamProject, string buildController, string buildName, string buildDescription, string user, string password) { string teamProjectPath = "$/" + teamProject; // Get a reference to our Team Foundation Server. TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collection), new System.Net.NetworkCredential(user, password)); tpc.EnsureAuthenticated(); VersionControlServer versionControl = tpc.GetService <VersionControlServer>(); IBuildServer buildServer = tpc.GetService <IBuildServer>(); //Create build definition and give it a name and desription IBuildDefinition buildDef = buildServer.CreateBuildDefinition(teamProject); buildDef.Name = buildName; buildDef.Description = buildDescription; buildDef.ContinuousIntegrationType = ContinuousIntegrationType.Individual; //CI //Controller and default build process template buildDef.BuildController = buildServer.GetBuildController(buildController); var defaultTemplate = buildServer.QueryProcessTemplates(teamProject).First(p => p.TemplateType == ProcessTemplateType.Default); buildDef.Process = defaultTemplate; buildDef.Workspace.AddMapping(teamProjectPath, "$(SourceDir)", WorkspaceMappingType.Map); buildDef.Workspace.AddMapping(teamProjectPath + "/Drops", "$(SourceDir)", WorkspaceMappingType.Cloak); //What to build string pattern = "$/*.sln"; var lists = versionControl.GetItems(pattern, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File); var processParams = new Dictionary <string, string[]>(); if (lists.Items.Any()) { var list = lists.Items .Select(i => i.ServerItem) .ToList(); processParams.Add("ProjectsToBuild", list.ToArray()); } processParams.Add("ConfigurationsToBuild", new[] { "Any CPU|Debug" }); buildDef.ProcessParameters = SerializeParams(processParams); buildDef.RetentionPolicyList.Clear(); buildDef.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Succeeded, 10, DeleteOptions.All); buildDef.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Failed, 10, DeleteOptions.All); buildDef.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Stopped, 1, DeleteOptions.All); buildDef.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.PartiallySucceeded, 10, DeleteOptions.All); //Lets save it buildDef.Save(); }
private static void CloneRetentionPolicies(IBuildDefinition bd, IBuildDefinition newBuildDefinition) { newBuildDefinition.RetentionPolicyList.Clear(); foreach (var retpol in bd.RetentionPolicyList) { newBuildDefinition.AddRetentionPolicy(retpol.BuildReason, retpol.BuildStatus, retpol.NumberToKeep, retpol.DeleteOptions); } }
public static void SetRetentionPolicies(IBuildDefinition definition, int succeeded, int partiallySucceeded, int failed, int stopped) { definition.RetentionPolicyList.Clear(); definition.AddRetentionPolicy(BuildReason.ValidateShelveset, BuildStatus.Succeeded, succeeded, DeleteOptions.Details | DeleteOptions.DropLocation | DeleteOptions.Label | DeleteOptions.TestResults); definition.AddRetentionPolicy(BuildReason.ValidateShelveset, BuildStatus.PartiallySucceeded, partiallySucceeded, DeleteOptions.All); definition.AddRetentionPolicy(BuildReason.ValidateShelveset, BuildStatus.Failed, failed, DeleteOptions.All); definition.AddRetentionPolicy(BuildReason.ValidateShelveset, BuildStatus.Stopped, stopped, DeleteOptions.All); definition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Succeeded, succeeded, DeleteOptions.Details | DeleteOptions.DropLocation | DeleteOptions.Label | DeleteOptions.TestResults); definition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.PartiallySucceeded, partiallySucceeded, DeleteOptions.All); definition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Failed, failed, DeleteOptions.All); definition.AddRetentionPolicy(BuildReason.Triggered, BuildStatus.Stopped, stopped, DeleteOptions.All); }
private static void UpdateRetentionPolicy(IBuildDefinition bd, BuildReason reason, int keep, DeleteOptions options, BuildStatus status) { var rp = bd.RetentionPolicyList.FirstOrDefault(r => r.BuildReason == reason && r.BuildStatus == status); if (rp == null) { bd.AddRetentionPolicy(reason, BuildStatus.Stopped, keep, options); } else { rp.NumberToKeep = keep; rp.DeleteOptions = options; } }
private static void CopyRetentionPolicies(IBuildDefinition source, IBuildDefinition target) { target.RetentionPolicyList.Clear(); foreach (var policy in source.RetentionPolicyList) { target.AddRetentionPolicy( policy.BuildReason, policy.BuildStatus, policy.NumberToKeep, policy.DeleteOptions ); } }
private static void CopyRetentionPolicies(IBuildDefinition source, IBuildDefinition target) { target.RetentionPolicyList.Clear(); foreach (var policy in source.RetentionPolicyList) { target.AddRetentionPolicy( policy.BuildReason, policy.BuildStatus, policy.NumberToKeep, policy.DeleteOptions ); } }
private static void UpdateRetentionPolicy(IBuildDefinition bd, BuildReason reason, int keep, DeleteOptions options, BuildStatus status) { var rp = bd.RetentionPolicyList.FirstOrDefault(r => r.BuildReason == reason && r.BuildStatus == status); if (rp == null) { bd.AddRetentionPolicy(reason, BuildStatus.Stopped, keep, options); } else { rp.NumberToKeep = keep; rp.DeleteOptions = options; } }
private static void CloneRetentionPolicies(IBuildDefinition bd, IBuildDefinition newBuildDefinition) { newBuildDefinition.RetentionPolicyList.Clear(); foreach (var retpol in bd.RetentionPolicyList) { newBuildDefinition.AddRetentionPolicy(retpol.BuildReason, retpol.BuildStatus, retpol.NumberToKeep, retpol.DeleteOptions); } }