public string CloneBuild(Uri buildDefinition, string newName, Branch source, Branch target) { string rootBranch = source.ServerPath; string targetBranch = target.ServerPath; var sourceBranchName = Path.GetFileName(rootBranch); var branchName = Path.GetFileName(targetBranch); var bd = this.buildServer.GetBuildDefinition(buildDefinition); var newBuildDefinition = this.buildServer.CreateBuildDefinition(bd.TeamProject); newBuildDefinition.Name = newName; newBuildDefinition.Description = bd.Description; newBuildDefinition.ContinuousIntegrationType = bd.ContinuousIntegrationType; newBuildDefinition.Enabled = bd.Enabled; CloneWorkspaceMappings(rootBranch, targetBranch, bd, newBuildDefinition); newBuildDefinition.BuildController = bd.BuildController; newBuildDefinition.ProcessParameters = bd.ProcessParameters; CloneDropLocation(sourceBranchName, branchName, bd, newBuildDefinition); CloneBuildSchedule(bd, newBuildDefinition); newBuildDefinition.ContinuousIntegrationQuietPeriod = bd.ContinuousIntegrationQuietPeriod; this.CloneBuildProcessTemplate(rootBranch, targetBranch, bd, newBuildDefinition); CloneRetentionPolicies(bd, newBuildDefinition); var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); CloneBuildSettings(rootBranch, targetBranch, parameters); CloneConfigurationFolderPath(rootBranch, targetBranch, bd, parameters); CloneTestSpecs(rootBranch, targetBranch, parameters); newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(parameters); newBuildDefinition.Save(); return(newBuildDefinition.ToString()); }
public string CloneBuildToProject(Uri buildDefinition, string newName, string targetProjectName) { var bd = this.buildServer.GetBuildDefinition(buildDefinition); string sourceProjectName = bd.TeamProject; var newBuildDefinition = this.buildServer.CreateBuildDefinition(targetProjectName); newBuildDefinition.Name = newName; newBuildDefinition.Description = bd.Description; newBuildDefinition.ContinuousIntegrationType = bd.ContinuousIntegrationType; newBuildDefinition.QueueStatus = bd.QueueStatus; CloneWorkspaceMappings(string.Concat("$/", sourceProjectName), string.Concat("$/", targetProjectName), bd, newBuildDefinition); newBuildDefinition.BuildController = bd.BuildController; newBuildDefinition.ProcessParameters = bd.ProcessParameters; CloneDropLocation(sourceProjectName, targetProjectName, bd, newBuildDefinition, false); CloneBuildSchedule(bd, newBuildDefinition); newBuildDefinition.ContinuousIntegrationQuietPeriod = bd.ContinuousIntegrationQuietPeriod; newBuildDefinition.Process = this.EnsureProjectHasBuildProcessTemplate(targetProjectName, bd.Process.ServerPath); CloneRetentionPolicies(bd, newBuildDefinition); var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); CloneStringParameters(sourceProjectName, targetProjectName, parameters); CloneItemsToBuild(sourceProjectName, targetProjectName, parameters); CloneConfigurationFolderPath(sourceProjectName, targetProjectName, bd, parameters); CloneTestSpecs(sourceProjectName, targetProjectName, parameters); newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(parameters); newBuildDefinition.Save(); return(newBuildDefinition.ToString()); }
public string CloneGitBuild(Uri buildDefinition, string newName) { var bd = this.buildServer.GetBuildDefinition(buildDefinition); var newBuildDefinition = this.buildServer.CreateBuildDefinition(bd.TeamProject); newBuildDefinition.Name = newName; newBuildDefinition.Description = bd.Description; newBuildDefinition.ContinuousIntegrationType = bd.ContinuousIntegrationType; newBuildDefinition.QueueStatus = bd.QueueStatus; newBuildDefinition.BuildController = bd.BuildController; newBuildDefinition.ProcessParameters = bd.ProcessParameters; newBuildDefinition.DefaultDropLocation = bd.DefaultDropLocation; var provider = CloneSourceProviders(newBuildDefinition, bd); newBuildDefinition.SetSourceProvider(provider); CloneBuildSchedule(bd, newBuildDefinition); newBuildDefinition.ContinuousIntegrationQuietPeriod = bd.ContinuousIntegrationQuietPeriod; newBuildDefinition.Process = bd.Process; CloneRetentionPolicies(bd, newBuildDefinition); var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(parameters); newBuildDefinition.Save(); return(newBuildDefinition.ToString()); }
public IEnumerable <string> GetProjectsToBuild(Uri buildDefinition) { var bd = this.buildServer.GetBuildDefinition(buildDefinition); var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); if (parameters.ContainsKey(BuildSettings)) { var buildSettings = parameters[BuildSettings] as BuildSettings; if (buildSettings == null) { return(new List <string>()); } if (buildSettings.HasProjectsToBuild) { return(buildSettings.ProjectsToBuild); } } else if (parameters.ContainsKey("ProjectsToBuild")) { return(parameters["ProjectsToBuild"] as string[]); } return(new List <string>()); }
public void ChangeProcessParameter(IEnumerable <Uri> buildDefinitions, string[] parameter, bool booleanParameter) { foreach (var bd in this.buildServer.QueryBuildDefinitionsByUri(buildDefinitions.ToArray())) { var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); if (parameters.ContainsKey(parameter[0])) { if (booleanParameter) { parameters[parameter[0]] = Convert.ToBoolean(parameter[1]); } else { parameters[parameter[0]] = parameter[1]; } } else { if (booleanParameter) { parameters.Add(parameter[0], Convert.ToBoolean(parameter[1])); } else { parameters.Add(parameter[0], parameter[1]); } } bd.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(parameters); bd.Save(); } }
public IList <DeliveryPipeline> GetPipelines() { IList <DeliveryPipeline> pipelines = new List <DeliveryPipeline>(); Uri collectionUri = new Uri(Uri); ProjectCollection = new TfsTeamProjectCollection(collectionUri); BuildServer = ProjectCollection.GetService <IBuildServer>(); CommonStructureService = ProjectCollection.GetService <ICommonStructureService>(); Registration = ProjectCollection.GetService <IRegistration>(); VersionControlServer = ProjectCollection.GetService <VersionControlServer>(); ClientHyperlinkService = ProjectCollection.GetService <TswaClientHyperlinkService>(); Name = ProjectCollection.CatalogNode.Resource.DisplayName; if (BuildServer.BuildServerVersion.ToString() == "v3") { TfsVersion = 2010; } else { TfsVersion = 2012; } foreach (ProjectInfo project in CommonStructureService.ListProjects()) { foreach (IBuildDefinition definition in BuildServer.QueryBuildDefinitions(project.Name)) { if (definition.Process.ServerPath.Contains("BuildProcessTemplates/PowerDelivery")) { IDictionary <string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(definition.ProcessParameters); if (processParams.ContainsKey("PowerShellScriptPath")) { string scriptPath = processParams["PowerShellScriptPath"] as string; string scriptName = System.IO.Path.GetFileNameWithoutExtension(scriptPath.Substring(scriptPath.LastIndexOf("/"))); string environmentName = definition.Name.Substring(definition.Name.LastIndexOf(" - ") + 3); DeliveryPipeline pipeline = pipelines.FirstOrDefault(p => p.ScriptName == scriptName); if (pipeline == null) { pipeline = new DeliveryPipeline(this, project, scriptName); pipelines.Add(pipeline); } PipelineEnvironment environment = new PipelineEnvironment(pipeline, environmentName, definition); pipeline.Environments.Add(environment); } } } } return(pipelines); }
public ProcessParametersViewModel(string _processparameters) { var processparameters = WorkflowHelpers.DeserializeProcessParameters(_processparameters); var myparams = new ObservableCollection <KeyPair>(); foreach (var element in processparameters) { var cfglist = new ObservableCollection <string>(); var pjtbdlist = new ObservableCollection <string>(); if (element.Key.ToString() == "ProjectsToBuild") { var projList = ((IEnumerable)element.Value).Cast <object>() .Select(x => x.ToString()) .ToArray(); foreach (var item in projList) { pjtbdlist.Add(item); } this.ProjectsToBuild = pjtbdlist; } if (element.Key.ToString() == "ConfigurationsToBuild") { var configList = ((IEnumerable)element.Value).Cast <object>() .Select(x => x.ToString()) .ToArray(); foreach (var item in configList) { cfglist.Add(item); } this.PlatformConfigurations = cfglist; } if (element.Key.ToString() == "AdvancedBuildSettings") { var kvp = new KeyPair(element.Key, element.Value.ToString()); myparams.Add(kvp); } if (element.Value.GetType().Name == "BuildSettings") { var bds = (BuildSettings)element.Value; PlatformConfigurationList pclist = new PlatformConfigurationList(); StringList pjb; } if (element.Value.GetType().Name == "TestSpecList") { var tsl = new ObservableCollection <TestSpec>(); var tslist = (TestSpecList)element.Value; foreach (var item in tslist) { tsl.Add(item); } testspeclist = tsl; } } procparameters = myparams; }
public void Promote(int buildNumber) { IBuildRequest request = BuildDefinition.CreateBuildRequest(); IDictionary <string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(request.ProcessParameters); processParams["PriorBuild"] = buildNumber.ToString(); request.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(processParams); IQueuedBuild queuedBuild = BuildDefinition.BuildServer.QueueBuild(request); }
public void UpdateOutputLocation(IEnumerable <Uri> buildDefinitions, string location) { foreach (var bd in this.buildServer.QueryBuildDefinitionsByUri(buildDefinitions.ToArray())) { var parameters = WorkflowHelpers.DeserializeProcessParameters(bd.ProcessParameters); if (parameters.ContainsKey("OutputLocation")) { parameters["OutputLocation"] = location; } else { parameters.Add("OutputLocation", location); } bd.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(parameters); bd.Save(); } }
private void LaunchBuild() { try { if (this.TeamProject.Expression == null) { var buildDetail = this.ActivityContext.GetExtension <IBuildDetail>(); this.TeamProject.Set(this.ActivityContext, buildDetail.TeamProject); } IBuildDefinition buildDefinition = this.bs.GetBuildDefinition(this.TeamProject.Get(this.ActivityContext), this.BuildDefinition.Get(this.ActivityContext)); IBuildRequest buildRequest = buildDefinition.CreateBuildRequest(); if (this.MSBuildArguments.Expression != null) { IDictionary <string, object> processParameters = WorkflowHelpers.DeserializeProcessParameters(buildRequest.ProcessParameters); IDictionary <string, object> definitionProcessParameters = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters); if (this.OverrideExistingMSBuildArguments.Get(this.ActivityContext) || !definitionProcessParameters.Keys.Contains(ProcessParameterMetadata.StandardParameterNames.MSBuildArguments)) { processParameters[ProcessParameterMetadata.StandardParameterNames.MSBuildArguments] = this.MSBuildArguments.Get(this.ActivityContext); } else { processParameters[ProcessParameterMetadata.StandardParameterNames.MSBuildArguments] = this.MSBuildArguments.Get(this.ActivityContext) + " " + definitionProcessParameters[ProcessParameterMetadata.StandardParameterNames.MSBuildArguments]; } buildRequest.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(processParameters); } this.qb = this.bs.QueueBuild(buildRequest); } catch (Exception) { this.qb = null; this.LogBuildError("There is a problem with the build definition referenced"); } }
public IList <BuildNumber> GetPromotableBuilds(int targetEnvironmentBuildNumber) { try { List <BuildNumber> promotableBuilds = new List <BuildNumber>(); IBuildDetailSpec buildSpec = Pipeline.Source.BuildServer.CreateBuildDetailSpec(BuildDefinition); buildSpec.InformationTypes = null; buildSpec.Status = BuildStatus.Succeeded; IBuildQueryResult buildDetails = Pipeline.Source.BuildServer.QueryBuilds(buildSpec); foreach (IBuildDetail buildDetail in buildDetails.Builds) { if (buildDetail.BuildFinished) { IDictionary <string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(buildDetail.ProcessParameters); Build build = new Build(buildDetail); int visibleBuildNumber = build.Number; if (EnvironmentName == "Production") { string buildUriString = buildDetail.Uri.ToString(); string buildUri = buildUriString.Contains("?") ? buildUriString.Substring(0, buildUriString.IndexOf("?")) : buildUriString; string buildUriPrefix = buildUri.Substring(0, buildUri.LastIndexOf("/") + 1); Uri commitBuildUri = new Uri(string.Format("{0}{1}", buildUriPrefix, processParams["PriorBuild"] as string)); IBuildDetail commitBuildDetail = BuildDefinition.BuildServer.GetMinimalBuildDetails(commitBuildUri); IDictionary <string, object> commitProcessParams = WorkflowHelpers.DeserializeProcessParameters(commitBuildDetail.ProcessParameters); visibleBuildNumber = Int32.Parse((string)commitProcessParams["PriorBuild"]); } else if (EnvironmentName != "Commit") { visibleBuildNumber = Int32.Parse((string)processParams["PriorBuild"]); } if (targetEnvironmentBuildNumber > 0) { if (visibleBuildNumber > targetEnvironmentBuildNumber) { promotableBuilds.Add(new BuildNumber(build, visibleBuildNumber)); } } else { promotableBuilds.Add(new BuildNumber(build, visibleBuildNumber)); } } } return(promotableBuilds); } catch (Exception ex) { throw new Exception(string.Format("Unable to get builds from TFS, error message was:\n\n{0}", ex.Message)); } }
private void RefreshStatus() { bool isQueued = false; _queuedBuildsView.Refresh(false); if (_queuedBuildsView.QueuedBuilds.Length > 0) { IQueuedBuild nextQueuedBuild = _queuedBuildsView.QueuedBuilds.OrderBy(b => b.QueuePosition).First(); if (nextQueuedBuild.Build != null) { LastBuildUri = nextQueuedBuild.Build.Uri; } LastStatus = new PipelineEnvironmentBuildStatus(BuildStatus.InProgress); isQueued = true; } if (!isQueued) { IOrderedEnumerable <IBuildDetail> existingBuilds = BuildDefinition.BuildServer.QueryBuilds(_buildSpec).Builds.OrderByDescending(b => b.StartTime); bool foundStatusBuild = false; foreach (IBuildDetail build in existingBuilds) { try { if (!foundStatusBuild) { IDictionary <string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(build.ProcessParameters); if (EnvironmentName == "Commit" || processParams.ContainsKey("PriorBuild")) { if (!isQueued) { LastStatus = new PipelineEnvironmentBuildStatus(build.Status); } LastBuildFinishTime = build.FinishTime; LastBuildUri = build.Uri; if (EnvironmentName == "Commit") { LastBuildNumber = new Build(build).Number.ToString(); } else if (EnvironmentName == "Production") { string buildUriString = build.Uri.ToString(); string buildUri = buildUriString.Contains("?") ? buildUriString.Substring(0, buildUriString.IndexOf("?")) : buildUriString; string buildUriPrefix = buildUri.Substring(0, buildUri.LastIndexOf("/") + 1); Uri commitBuildUri = new Uri(string.Format("{0}{1}", buildUriPrefix, processParams["PriorBuild"] as string)); IBuildDetail buildDetail = BuildDefinition.BuildServer.GetMinimalBuildDetails(commitBuildUri); processParams = WorkflowHelpers.DeserializeProcessParameters(buildDetail.ProcessParameters); LastBuildNumber = processParams["PriorBuild"] as string; } else { LastBuildNumber = processParams["PriorBuild"] as string; } foundStatusBuild = true; break; } } } catch (Exception) { } } if (foundStatusBuild) { return; } else { LastBuildNumber = "0"; LastBuildUri = null; LastStatus = new PipelineEnvironmentBuildStatus(BuildStatus.None); LastBuildFinishTime = DateTime.MinValue; } } }
public BuildDefinitionViewModel(IBuildDefinition build) { this.Name = build.Name; this.BuildDefinition = build; this.Uri = build.Uri; this.TeamProject = build.TeamProject; this.ContinuousIntegrationType = GetFriendlyTriggerName(build.ContinuousIntegrationType); if ((build.ContinuousIntegrationType == Microsoft.TeamFoundation.Build.Client.ContinuousIntegrationType.Schedule || build.ContinuousIntegrationType == Microsoft.TeamFoundation.Build.Client.ContinuousIntegrationType.ScheduleForced) && build.Schedules.Count > 0) { this.ContinuousIntegrationType = string.Format("{0} - {1}", this.ContinuousIntegrationType, ConvertTime(build.Schedules[0].StartTime.ToString(CultureInfo.CurrentCulture))); } else if (build.ContinuousIntegrationType == Microsoft.TeamFoundation.Build.Client.ContinuousIntegrationType.Gated) { this.ContinuousIntegrationType = string.Format("{0} - {1}", this.ContinuousIntegrationType, build.BatchSize); } else if (build.ContinuousIntegrationType == Microsoft.TeamFoundation.Build.Client.ContinuousIntegrationType.Batch) { this.ContinuousIntegrationType = string.Format("{0} - {1}", this.ContinuousIntegrationType, build.ContinuousIntegrationQuietPeriod); } this.BuildController = build.BuildController != null ? build.BuildController.Name : NotAvailable; this.Process = build.Process != null?Path.GetFileNameWithoutExtension(build.Process.ServerPath) : NotAvailable; this.Description = build.Description; this.DefaultDropLocation = build.DefaultDropLocation; this.Id = Convert.ToInt32(build.Id); this.QueueStatus = build.QueueStatus.ToString(); this.Enabled = build.QueueStatus != DefinitionQueueStatus.Disabled; this.IsGitProject = build.SourceProviders.Any(s => s.Name.ToUpperInvariant().Contains("GIT")); this.IsTfvcProject = !this.IsGitProject; this.LastModifiedBy = build.Workspace.LastModifiedBy; this.LastModifiedDate = build.Workspace.LastModifiedDate; try { var parameters = WorkflowHelpers.DeserializeProcessParameters(build.ProcessParameters); this.OutputLocation = parameters.ContainsKey("OutputLocation") ? parameters["OutputLocation"].ToString() : "SingleFolder"; if (parameters.ContainsKey("AgentSettings")) { try { if (parameters["AgentSettings"].GetType() == typeof(AgentSettings)) { AgentSettings ags = (AgentSettings)parameters["AgentSettings"]; if (ags.HasTags) { this.AgentTags = ags.Tags.ToString(); } } else if (parameters["AgentSettings"].GetType() == typeof(BuildParameter)) { BuildParameter ags = (BuildParameter)parameters["AgentSettings"]; { var jstt = JsonConvert.DeserializeObject <AgentSettingsBuildParameter>(ags.Json); if (jstt.Tags != null && jstt.Tags.Count > 0) { this.AgentTags = string.Join(", ", jstt.Tags.ToArray()); } } } } catch (Exception) { this.AgentTags = "Failed to determine"; } } } catch (Exception) { this.OutputLocation = "Failed to determine"; } }
private void UpdateBuildDefinitions() { if (this.SelectedTeamProject == null) { return; } #if !DEBUG try { #endif using (new WaitCursor()) { if (this.dispatcherTimer.IsEnabled) { this.dispatcherTimer.Stop(); } if (this.viewmodel.SelectedBuildView == BuildView.BuildDefinitions) { IEnumerable <IBuildDefinition> builds; if (this.SelectedController == BuildManagerViewModel.AllItem) { builds = this.SelectedTeamProject == BuildManagerViewModel.AllItem ? this.repository.AllBuildDefinitions : this.repository.GetBuildDefinitionsForTeamProject(this.SelectedTeamProject); } else { IBuildController controller = this.repository.GetController(this.SelectedController); builds = this.SelectedTeamProject == BuildManagerViewModel.AllItem ? this.repository.GetBuildDefinitions(controller) : this.repository.GetBuildDefinitions(controller, this.SelectedTeamProject); } builds = this.viewmodel.IncludeDisabledBuildDefinitions ? builds : builds.Where(b => b.QueueStatus != DefinitionQueueStatus.Disabled); if (!string.IsNullOrWhiteSpace(this.viewmodel.BuildDefinitionFilter)) { // if it starts with $/ then we seach on workspace mappings if (this.viewmodel.BuildDefinitionFilter.StartsWith(@"$/", StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrWhiteSpace(this.viewmodel.BuildDefinitionFilter)) { List <IBuildDefinition> builds2 = new List <IBuildDefinition>(); var filter = this.viewmodel.BuildDefinitionFilter; builds2.AddRange(builds.Where(b => b.Workspace.Mappings.Any(mapping => mapping.ServerItem.StartsWith(filter, StringComparison.OrdinalIgnoreCase)))); var buildDefinitions = builds2.ToArray(); this.viewmodel.AssignBuildDefinitions(buildDefinitions); this.lblCount.Content = buildDefinitions.Count(); } } else if (this.viewmodel.BuildDefinitionFilter.StartsWith(@"*", StringComparison.OrdinalIgnoreCase)) { // if it starts with * then we are going to search Process Parameters if (this.viewmodel.BuildDefinitionFilter == "*" || this.viewmodel.BuildDefinitionFilter == "**") { return; } List <IBuildDefinition> builds2 = new List <IBuildDefinition>(); foreach (IBuildDefinition b in builds) { var processParameters = WorkflowHelpers.DeserializeProcessParameters(b.ProcessParameters); // if it starts with ** we do a contains, otherwise it starts with * and we do a compare. if (this.viewmodel.BuildDefinitionFilter.StartsWith(@"**", StringComparison.OrdinalIgnoreCase)) { bool found = false; foreach (var parameter in processParameters) { // some process parameters are arrays so we need to look at each key value pair in the arrays if (parameter.Value.GetType().GetElementType() == typeof(string)) { string[] arr = ((IEnumerable)parameter.Value).Cast <object>().Select(x => x.ToString()).ToArray(); if (arr.Any(s => s.IndexOf(this.viewmodel.BuildDefinitionFilter.Replace("*", string.Empty), StringComparison.OrdinalIgnoreCase) >= 0)) { builds2.Add(b); found = true; } } else { if (parameter.Value.ToString().IndexOf(this.viewmodel.BuildDefinitionFilter.Replace("*", string.Empty), StringComparison.OrdinalIgnoreCase) >= 0) { builds2.Add(b); found = true; } } if (!found && this.viewmodel.BuildDefinitionFilter.StartsWith(@"***", StringComparison.OrdinalIgnoreCase)) { Regex r = new Regex(@"<this:Process\..*>*" + this.viewmodel.BuildDefinitionFilter.Replace("*", string.Empty) + ".*</", RegexOptions.IgnoreCase); Match match = r.Match(b.Process.Parameters); if (match.Success) { builds2.Add(b); found = true; } } if (found) { break; } } } else { bool found = false; foreach (var parameter in processParameters) { if (parameter.Value.GetType().GetElementType() == typeof(string)) { string[] arr = ((IEnumerable)parameter.Value).Cast <object>() .Select(x => x.ToString()) .ToArray(); if (arr.Any(s => string.Compare(s, this.viewmodel.BuildDefinitionFilter.Replace("*", string.Empty), StringComparison.OrdinalIgnoreCase) == 0)) { builds2.Add(b); found = true; } } else { if (string.Compare(parameter.Value.ToString(), this.viewmodel.BuildDefinitionFilter.Replace("*", string.Empty), StringComparison.OrdinalIgnoreCase) == 0) { builds2.Add(b); found = true; } } if (found) { break; } } } } var buildDefinitions = builds2.ToArray(); this.viewmodel.AssignBuildDefinitions(buildDefinitions); this.lblCount.Content = buildDefinitions.Count(); } else { var filter = this.viewmodel.BuildDefinitionFilter.ToUpperInvariant(); builds = builds.Where(b => b.Name.ToUpperInvariant().Contains(filter)).ToArray(); var buildDefinitions = builds as IBuildDefinition[]; this.viewmodel.AssignBuildDefinitions(buildDefinitions); this.lblCount.Content = buildDefinitions.Count(); } } else { var buildDefinitions = builds as IBuildDefinition[] ?? builds.ToArray(); this.viewmodel.AssignBuildDefinitions(buildDefinitions); this.lblCount.Content = buildDefinitions.Count(); } } else if (this.viewmodel.SelectedBuildView == BuildView.Builds) { this.UpdateBuilds(); } else if (this.viewmodel.SelectedBuildView == BuildView.BuildProcessTemplates) { this.UpdateBuildProcessTemplates(); } else if (this.viewmodel.SelectedBuildView == BuildView.BuildResources) { this.UpdateBuildResources(); } } #if !DEBUG } catch (Exception ex) { this.DisplayError(ex); } #endif }
private void ButtonImport_OnClick(object sender, RoutedEventArgs e) { foreach (var item in this.DataGridBuildsToImport.Items) { BuildImport bi = item as BuildImport; try { if (bi == null) { return; } if (!File.Exists(bi.JsonFile)) { bi.Status = "Failed"; bi.StatusImage = "Graphics/Failed.png"; bi.Message = "File not found"; } else { ExportedBuildDefinition exdef = JsonConvert.DeserializeObject <ExportedBuildDefinition>(File.ReadAllText(bi.JsonFile)); var newBuildDefinition = this.buildServer.CreateBuildDefinition(this.lableTeamProject.Content.ToString()); newBuildDefinition.Name = exdef.Name; newBuildDefinition.Description = exdef.Description; newBuildDefinition.ContinuousIntegrationType = exdef.ContinuousIntegrationType; newBuildDefinition.ContinuousIntegrationQuietPeriod = exdef.ContinuousIntegrationQuietPeriod; newBuildDefinition.QueueStatus = exdef.QueueStatus; if (exdef.SourceProviders.All(s => s.Name != "TFGIT")) { foreach (var mapping in exdef.Mappings) { newBuildDefinition.Workspace.AddMapping(mapping.ServerItem, mapping.LocalItem, mapping.MappingType); } } newBuildDefinition.RetentionPolicyList.Clear(); foreach (var ret in exdef.RetentionPolicyList) { newBuildDefinition.AddRetentionPolicy(ret.BuildReason, ret.BuildStatus, ret.NumberToKeep, ret.DeleteOptions); } foreach (var sp in exdef.SourceProviders) { var provider = newBuildDefinition.CreateInitialSourceProvider(sp.Name); if (exdef.SourceProviders.All(s => s.Name == "TFGIT")) { provider.Fields["RepositoryName"] = sp.Fields["RepositoryName"]; provider.Fields["DefaultBranch"] = sp.Fields["DefaultBranch"]; provider.Fields["CIBranches"] = sp.Fields["CIBranches"]; provider.Fields["RepositoryUrl"] = sp.Fields["RepositoryUrl"]; } newBuildDefinition.SetSourceProvider(provider); } newBuildDefinition.BuildController = this.buildServer.GetBuildController(exdef.BuildController); var x = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()); if (x.All(p => p.ServerPath != exdef.ProcessTemplate)) { bi.Status = "Failed"; bi.StatusImage = "Graphics/Failed.png"; bi.Message = "Process Template not found - " + exdef.ProcessTemplate; continue; } newBuildDefinition.Process = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()).First(p => p.ServerPath == exdef.ProcessTemplate); newBuildDefinition.DefaultDropLocation = exdef.DefaultDropLocation; foreach (var sched in exdef.Schedules) { var newSched = newBuildDefinition.AddSchedule(); newSched.DaysToBuild = sched.DaysToBuild; newSched.StartTime = sched.StartTime; newSched.TimeZone = sched.TimeZone; } var process = WorkflowHelpers.DeserializeProcessParameters(newBuildDefinition.ProcessParameters); foreach (var param in exdef.ProcessParameters) { switch (param.Key) { case "BuildSettings": if (exdef.ProjectsToBuild != null) { process.Add(param.Key, new BuildSettings { ProjectsToBuild = exdef.ProjectsToBuild, PlatformConfigurations = exdef.ConfigurationsToBuild }); } break; case "AgentSettings": if (exdef.TfvcAgentSettings != null) { process.Add(param.Key, (AgentSettings)exdef.TfvcAgentSettings); } else if (exdef.GitAgentSettings != null) { process.Add(param.Key, exdef.GitAgentSettings); } break; case "TestSpecs": if (exdef.AgileTestSpecs != null) { process.Add(param.Key, exdef.AgileTestSpecs.ToSpecList()); } break; default: Newtonsoft.Json.Linq.JArray arrayItem = param.Value as Newtonsoft.Json.Linq.JArray; if (arrayItem == null) { Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject; if (objectItem == null) { if (param.Key == "CleanWorkspace") { process.Add(param.Key, (CleanWorkspaceOption)Enum.Parse(typeof(CleanWorkspaceOption), param.Value.ToString())); } else if (param.Key == "RunCodeAnalysis") { process.Add(param.Key, (CodeAnalysisOption)Enum.Parse(typeof(CodeAnalysisOption), param.Value.ToString())); } else { process.Add(param.Key, param.Value); } } else { Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString()); process.Add(param.Key, paramItem); } } else { string[] arrayItemList = new string[arrayItem.Count]; for (int i = 0; i < arrayItem.Count; i++) { arrayItemList[i] = arrayItem[i].ToString(); } process.Add(param.Key, arrayItemList); } break; } } if (exdef.BuildReasons != null) { foreach (var key in exdef.BuildReasons.Keys) { if (process.ContainsKey(key)) { process[key] = exdef.BuildReasons[key]; } } } if (exdef.IntegerParameters != null) { foreach (var key in exdef.IntegerParameters.Keys) { if (process.ContainsKey(key)) { process[key] = exdef.IntegerParameters[key]; } } } if (exdef.BuildVerbosities != null) { foreach (var key in exdef.BuildVerbosities.Keys) { if (process.ContainsKey(key)) { process[key] = exdef.BuildVerbosities[key]; } } } newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process); newBuildDefinition.Save(); bi.Status = "Succeeded"; bi.StatusImage = "Graphics/Succeeded.png"; bi.Message = string.Empty; } } catch (Exception ex) { bi.Status = "Failed"; bi.StatusImage = "Graphics/Failed.png"; bi.Message = ex.Message; } finally { this.DataGridBuildsToImport.ItemsSource = null; this.DataGridBuildsToImport.ItemsSource = this.buildFiles; } } }