private static void runByBuild(ProjectType project, Build build) { Console.WriteLine($"Build Id:{build.Id}"); try { var buildFailedPBIId = 0; var wiqlResult_PBI = WorkItemResult.Query(ProjectType.b, $@" SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] = 'Product Backlog Item' AND [System.Title] = '{Config.PBITitle}' AND [System.IterationPath] = '{WorkItemResult.GetCurrentIteration(ProjectType.b)}'"); // create a PBI, if it is not exist if (wiqlResult_PBI.WorkItems.Any()) { buildFailedPBIId = wiqlResult_PBI.WorkItems.Select(wi => wi.Id).Single(); } else { buildFailedPBIId = WorkItemResult.Create(ProjectType.b, WorkItemType.PBI, Config.PBITitle, Area.CICD); Console.WriteLine($"pbi created:[id:{buildFailedPBIId}][title:{Config.PBITitle}]"); } // create a task, if there is no tag in the build if (!BuildResult.GetTags(project, build.Id).Contains(Config.TagName)) { var taskTitle = _taskTitleFormat .Replace("$Date", DateTime.Now.ToString(@"yyyy/MM/dd")) .Replace("$Repository", RepositoryResult.Get(project, build.Repository.Id).Name); var description = (@"<a href=""$url"" aria-label=""CTRL+Click or CTRL+Enter to follow link $url"">$url</a>") .Replace("$url", build.Links.Web.Href); var taskId = WorkItemResult.Create(ProjectType.b, WorkItemType.Task, taskTitle, Area.CICD, build.RequestedFor.UniqueName, description, buildFailedPBIId); BuildResult.AddTag(project, build.Id, Config.TagName); Console.WriteLine($"task created:[id:{taskId}][title:{taskTitle}]"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }