public IList <IBuild> QueryBuilds() { return(_buildDefinition.QueryBuilds().Select(b => { var id = b.Uri.AbsoluteUri.Substring(b.Uri.AbsoluteUri.LastIndexOf('/') + 1); string duration = string.Empty; if (b.Status != Microsoft.TeamFoundation.Build.Client.BuildStatus.NotStarted && b.Status != Microsoft.TeamFoundation.Build.Client.BuildStatus.None && b.Status != Microsoft.TeamFoundation.Build.Client.BuildStatus.Stopped) { if (b.Status == Microsoft.TeamFoundation.Build.Client.BuildStatus.InProgress) { duration += " / " + GetDuration(DateTime.Now - b.StartTime); } else { duration += " / " + GetDuration(b.FinishTime - b.StartTime); } } return new BuildInfo { Id = id, Label = b.BuildNumber, StartDate = b.StartTime, Status = ConvertStatus(b.Status), IsFinished = b.BuildFinished, Description = GetStatus(b) + duration, Revision = b.SourceGetVersion, Url = _isWebServer ? _hostname + "/" + _teamCollection + "/" + _projectName + "/_build#buildUri=" + Uri.EscapeDataString(b.Uri.AbsoluteUri) + "&_a=summary" : "http://" + _hostname + ":8080/tfs/Build/Build.aspx?artifactMoniker=" + id, }; }).Cast <IBuild>().ToList()); }
private static TFS.Common.WorkflowConfig.AssociatedBuildDefinition ConvertToAssociatedBuildDefinition(IBuildDefinition res) { var abd = new LabWorkflowManager.TFS.Common.WorkflowConfig.AssociatedBuildDefinition(); abd.Name = res.Name; abd.BuildControllerName = res.BuildController != null ? res.BuildController.Name : string.Empty; abd.BuildControllerUri = res.BuildControllerUri != null ? res.BuildControllerUri.ToString() : string.Empty; abd.ContinuousIntegrationQuietPeriod = res.ContinuousIntegrationQuietPeriod; abd.ContinuousIntegrationType = (LabWorkflowManager.TFS.Common.WorkflowConfig.BuildDefinitionContinuousIntegrationType)res.ContinuousIntegrationType; abd.DateCreated = res.DateCreated; abd.Description = res.Description; abd.Id = res.Id; abd.LastBuildUri = res.LastBuildUri != null ? res.LastBuildUri.ToString() : string.Empty; abd.LastGoodBuildLabel = res.LastGoodBuildLabel; abd.LastGoodBuildUri = res.LastGoodBuildUri != null ? res.LastGoodBuildUri.ToString() : string.Empty; abd.Builds = res.QueryBuilds().Select(o => new LabWorkflowManager.TFS.Common.WorkflowConfig.AssociatedBuildDetail() { Uri = o.Uri.ToString(), LabelName = o.LabelName }).ToList(); abd.Uri = res.Uri.ToString(); return abd; }
protected override void Execute(CodeActivityContext context) { workspace = context.GetValue(this.Workspace); IBuildDefinition buildDef = context.GetValue(this.BuildDefinition); DateTime? comparison = null; var details = buildDef.QueryBuilds().Where(x => x.Status == BuildStatus.Succeeded).OrderBy(x => x.StartTime); if (details.Count() > 0) { comparison = details.Last().StartTime; } if (!comparison.HasValue) { return; } IEnumerable history = workspace.VersionControlServer.QueryHistory("$/" + context.GetValue(ProjectName), VersionSpec.Latest, 0, RecursionType.Full, null, new DateVersionSpec(comparison.Value), VersionSpec.Latest, Int32.MaxValue, true, false); foreach (Changeset c in history.OfType<Changeset>().OrderBy(x => x.CreationDate)) { foreach (var change in c.Changes.Where(x => x.Item.ItemType == ItemType.File && x.Item.ServerItem.Split('/').Last().ToLower().Contains(".sql") && (x.ChangeType != (ChangeType.Delete | ChangeType.SourceRename | ChangeType.Rename)))) { string fileName = change.Item.ServerItem.Split('/').Last(); WorkingFolder wf = workspace.TryGetWorkingFolderForServerItem(change.Item.ServerItem); if (wf != null && !string.IsNullOrEmpty(wf.LocalItem)) { context.WriteBuildMessage(string.Format("SQL File found: {0}", fileName)); } } } }
private IBuildDetail GetPreviousDaySuccessfulBuildDetail(IBuildDefinition buildDefinition) { IBuildDetail[] buildDetail = buildDefinition.QueryBuilds(); var previousBuild = buildDetail.Where(b => b.Status == Microsoft.TeamFoundation.Build.Client.BuildStatus.Succeeded) .Where(d => d.FinishTime.Date != DateTime.Now.Date) .OrderByDescending(f => f.FinishTime) .First(); return previousBuild; }
private IBuildDetail GetLatestSuccessfulBuildDetail(IBuildDefinition buildDefinition) { IBuildDetail[] buildDetail = buildDefinition.QueryBuilds(); var build = buildDetail.Where(b => b.Status == Microsoft.TeamFoundation.Build.Client.BuildStatus.Succeeded) .OrderByDescending(f => f.FinishTime) .First(); return build; }
public bool PrintDefinitionDetails( IBuildDefinition definition, bool printParams = false, bool printPolicies = false, bool printBuilds = false, string filterKeys = null, string filterValues = null) { var filtered = false; string[] paras = null; if (filterKeys != null) paras = filterKeys.Split(','); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("{0}", definition.Name); Console.ResetColor(); Console.WriteLine("\tTrigger: '{0}'\tDefault drop location: '{1}'", definition.TriggerType, definition.DefaultDropLocation); if (printParams) { var processParameters = definition.ProcessParameters; var paramValues = WorkflowHelpers.DeserializeProcessParameters(processParameters); var values = ((filterKeys == null) ? paramValues : paramValues.Where(p => paras.Contains(p.Key))).ToArray(); if (filterValues != null) { var filters = filterValues.Split(','); //TODO } if (values.Any()) { Console.Write("Params"); foreach (var param in values) { //if (param.Key == "EnsambladosACompartir" && param.Value.ToString().Contains("*")) // filtered = true; Console.WriteLine("\t'{0}': '{1}'", param.Key, PrintObject(param.Value)); } } } if (printPolicies) { Console.WriteLine("Retention Policies"); foreach (var retentionPolicy in definition.RetentionPolicyList) { Console.WriteLine("\t{0}: {1}, Delete: {2}", retentionPolicy.BuildStatus, retentionPolicy.NumberToKeep, retentionPolicy.DeleteOptions); } } if (printBuilds) { var builds = definition.QueryBuilds(); Console.WriteLine("\tBuilds: {0}", builds.Count()); } return filtered; }