Пример #1
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            List <AdoBuildResultRow> rows = new List <AdoBuildResultRow>();

            if (!JenkinsConsoleUtility.TryGetArgVar(out pat, argsLc, "days"))
            {
                days = 3;
            }
            pat = JenkinsConsoleUtility.GetArgVar(argsLc, "pat");
            string kustoConfigFile = JenkinsConsoleUtility.GetArgVar(argsLc, "kustoConfig");

            if (!File.Exists(kustoConfigFile))
            {
                throw new ArgumentException("kustoConfig file does not exist.");
            }
            string      kustoConfigJson = File.ReadAllText(kustoConfigFile);
            KustoConfig kustoConfig     = JsonConvert.DeserializeObject <KustoConfig>(kustoConfigJson);

            kustoWriter = new KustoWriter(kustoConfig);

            Task <string> getBuildsTask = Task.Run(GetBuilds);
            string        buildJson     = getBuildsTask.Result;

            var builds     = JsonConvert.DeserializeObject <GetBuildsResult>(buildJson);
            var tabbedJson = JsonConvert.SerializeObject(builds, Formatting.Indented);

            File.WriteAllText("temp.json", tabbedJson);
            var buildReports = ProcessBuildList(builds.value);

            foreach (var eachReportPair in buildReports)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.DarkCyan, eachReportPair.Value.name);
                foreach (var eachDailyResultPair in eachReportPair.Value.dailyResults)
                {
                    if (eachDailyResultPair.Key > days)
                    {
                        continue; // Skip the old tests
                    }
                    DateTime date;
                    int      passed, failed, others, total;
                    BuildReport.Count(eachDailyResultPair.Value, out date, out passed, out failed, out others, out total);
                    JcuUtil.FancyWriteToConsole(
                        ConsoleColor.White, eachDailyResultPair.Key, " days ago(", date, "): (",
                        ConsoleColor.Green, "P: ", passed, ConsoleColor.White, "/",
                        ConsoleColor.Red, "F:", failed, ConsoleColor.White, "/",
                        ConsoleColor.DarkYellow, "O:", others, ConsoleColor.White, "/",
                        ConsoleColor.Cyan, "T:", total, ConsoleColor.White, ")");
                    rows.Add(new AdoBuildResultRow(eachReportPair.Value.name, passed, failed, others, total, date));
                }
            }

            bool success = kustoWriter.WriteDataForTable(false, rows);

            return(success && builds.value.Count > 0 ? 0 : 1);
        }
Пример #2
0
        private async Task <int> ExecuteAsync(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            List <AdoBuildResultRow> rows = new List <AdoBuildResultRow>();

            string daysStr;

            if (!JenkinsConsoleUtility.TryGetArgVar(out daysStr, argsLc, "days") || !int.TryParse(daysStr, out days))
            {
                days = 3;
            }
            pat = JenkinsConsoleUtility.GetArgVar(argsLc, "pat");
            string kustoConfigFile = JenkinsConsoleUtility.GetArgVar(argsLc, "kustoConfig");

            if (!File.Exists(kustoConfigFile))
            {
                throw new ArgumentException("kustoConfig file does not exist.");
            }
            string      kustoConfigJson = File.ReadAllText(kustoConfigFile);
            KustoConfig kustoConfig     = JsonConvert.DeserializeObject <KustoConfig>(kustoConfigJson);

            kustoWriter = new KustoWriter(kustoConfig);

            GetPipelinesResult pipelines = await MakeAdoApiCall <GetPipelinesResult>(pipelinesUrl, "pipelines.json");

            if (!FilterPipelines(pipelines.value))
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Red, "No pipelines found in expected folder: " + expectedFolderPrefix);
                return(1);
            }

            int buildsWritten = 0;

            foreach (var eachPipeline in pipelines.value)
            {
                GetBuildsResult builds = await MakeAdoApiCall <GetBuildsResult>(buildsUrl.Replace("{definitionId}", eachPipeline.id.ToString()), "builds" + eachPipeline.id + ".json");

                var buildReports = ProcessBuildList(builds.value);
                foreach (var eachReportPair in buildReports)
                {
                    JcuUtil.FancyWriteToConsole(ConsoleColor.DarkCyan, eachReportPair.Value.name);
                    foreach (var eachDailyResultPair in eachReportPair.Value.dailyResults)
                    {
                        if (eachDailyResultPair.Key > days)
                        {
                            continue; // Skip the old tests
                        }
                        DateTime date;
                        int      passed, failed, others, total;
                        BuildReport.Count(eachDailyResultPair.Value, out date, out passed, out failed, out others, out total);
                        JcuUtil.FancyWriteToConsole(
                            ConsoleColor.White, eachDailyResultPair.Key, " days ago(", date, "): (",
                            ConsoleColor.Green, "P: ", passed, ConsoleColor.White, "/",
                            ConsoleColor.Red, "F:", failed, ConsoleColor.White, "/",
                            ConsoleColor.DarkYellow, "O:", others, ConsoleColor.White, "/",
                            ConsoleColor.Cyan, "T:", total, ConsoleColor.White, ")");
                        rows.Add(new AdoBuildResultRow(eachReportPair.Value.name, passed, failed, others, total, date));
                    }
                }
                buildsWritten += builds.value.Count;
            }

            bool success = kustoWriter.WriteDataForTable(false, rows);

            return(success && buildsWritten > 0 ? 0 : 1);
        }