public static TestTitleData Load(Dictionary <string, string> argsLc)
        {
            if (testTitleData != null)
            {
                return(testTitleData);
            }

            string filepath;

            // If testTitleData path is provided, try to load the file
            if (JenkinsConsoleUtility.TryGetArgVar(out filepath, argsLc, "testTitleData") && !string.IsNullOrEmpty(filepath))
            {
                _LoadTestTitleData(filepath);
            }
            // If PF_TEST_TITLE_DATA_JSON exists, get testTitleData path from it, and try to load the file
            filepath = Environment.GetEnvironmentVariable("PF_TEST_TITLE_DATA_JSON");
            if (!string.IsNullOrEmpty(filepath))
            {
                _LoadTestTitleData(filepath);
            }

            if (testTitleData == null)
            {
                Console.WriteLine("ERROR: Must use testTitleData");
                throw new Exception("ERROR: Must use testTitleData");
            }

            return(testTitleData);
        }
Esempio n. 2
0
        private void ParseInputs(Dictionary <string, string> argsCased)
        {
            if (!JenkinsConsoleUtility.TryGetArgVar(out BBL_VERSIONS, argsCased, "BBL_VERSIONS"))
            {
                BBL_VERSIONS = "3.0.0;2.0.1";
            }

            string tempGapThresholds = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempGapThresholds, argsCased, "GAP_MAX_THRESHOLDS"))
            {
                try { GAP_MAX_THRESHOLDS = tempGapThresholds.Split(';').Select(s => int.Parse(s)).ToArray(); } catch (Exception) { }
            }

            string tempStandby = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempStandby, argsCased, "STANDBY_MIN_THRESHOLDS"))
            {
                try { STANDBY_MIN_THRESHOLDS = tempStandby.Split(';').Select(s => int.Parse(s)).ToArray(); } catch (Exception) { }
            }

            string tempMaxCap = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempMaxCap, argsCased, "MAX_CAPACITY_PERCENT_THRESHOLDS"))
            {
                try { MAX_CAPACITY_PERCENT_THRESHOLDS = tempMaxCap.Split(';').Select(s => int.Parse(s)).ToArray(); } catch (Exception) { }
            }

            string tempCycleDuration = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempCycleDuration, argsCased, "CYCLE_DURATION_MINS"))
            {
                try { CYCLE_DURATION_MINS = TimeSpan.FromMinutes(double.Parse(tempCycleDuration)); } catch (Exception) { }
            }

            string tempCyclePeriod = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempCyclePeriod, argsCased, "CYCLE_PERIOD_SEC"))
            {
                try { CYCLE_PERIOD_SEC = TimeSpan.FromSeconds(double.Parse(tempCyclePeriod)); } catch (Exception) { }
            }

            string tempRetryDelay = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempRetryDelay, argsCased, "RETRY_DELAY_SEC"))
            {
                try { RETRY_DELAY_SEC = TimeSpan.FromSeconds(double.Parse(tempRetryDelay)); } catch (Exception) { }
            }

            string tempRetryCount = "";

            if (JenkinsConsoleUtility.TryGetArgVar(out tempRetryCount, argsCased, "RETRY_COUNT"))
            {
                try { RETRY_COUNT = int.Parse(tempRetryCount); } catch (Exception) { }
            }
        }
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            string destFile, workspacePath;

            JenkinsConsoleUtility.TryGetArgVar(out destFile, argsLc, "destFile");
            JenkinsConsoleUtility.TryGetArgVar(out workspacePath, argsLc, "workspacePath");
            var sdkName   = JenkinsConsoleUtility.GetArgVar(argsLc, "sdkName");
            var sdkGenKey = GetSdkGenKey(sdkName);

            if (argsLc.ContainsKey("apispecpath"))
            {
                _apiSpecPath = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecPath");
            }
            else if (argsLc.ContainsKey("apispecgiturl"))
            {
                _apiSpecGitUrl = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecGitUrl");
            }
            else if (argsLc.ContainsKey("apispecpfurl"))
            {
                _apiSpecPfUrl = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecPfUrl");
            }
            else
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Api-Spec input not defined.  Please input one of: apiSpecPath, apiSpecGitUrl, apiSpecPfUrl");
                return(1);
            }

            var versionJson = GetApiJson("SdkManualNotes.json");
            var sdkNotes    = JsonWrapper.DeserializeObject <SdkManualNotes>(versionJson);

            if (!sdkNotes.sdkVersion.TryGetValue(sdkGenKey, out sdkVersionString))
            {
                JenkinsConsoleUtility.FancyWriteToConsole("SdkManualNotes.json does not contain: " + sdkGenKey);
                JenkinsConsoleUtility.FancyWriteToConsole("SdkManualNotes.json:\n" + versionJson);
                return(1);
            }

            var sdkPieces = sdkVersionString.Split('.');

            major = sdkPieces[0]; minor = sdkPieces[1]; date = sdkPieces[sdkPieces.Length - 1];
            set   = true;

            // Write this to a Jenkins environment variable file, if defined
            if (!string.IsNullOrEmpty(destFile))
            {
                using (var outputFile = new StreamWriter(Path.Combine(workspacePath, destFile)))
                {
                    outputFile.WriteLine("sdkVersion = " + sdkVersionString);
                    outputFile.WriteLine("sdkDate = " + date);
                    JenkinsConsoleUtility.FancyWriteToConsole("sdkVersion = " + sdkVersionString);
                    JenkinsConsoleUtility.FancyWriteToConsole("sdkDate = " + date);
                }
            }
            return(0);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private int?GetFixedAlertDays(Dictionary <string, string> argsLc)
        {
            string alertDaysStr;

            JenkinsConsoleUtility.TryGetArgVar(out alertDaysStr, argsLc, "alertDays");
            int alertDays;

            if (int.TryParse(alertDaysStr, out alertDays))
            {
                return(alertDays);
            }

            return(null);
        }
Esempio n. 6
0
        public static TestTitleData Load(Dictionary <string, string> argsLc)
        {
            if (testTitleData != null)
            {
                return(testTitleData);
            }

            string workspacePath = "";

            JenkinsConsoleUtility.TryGetArgVar(out workspacePath, argsLc, "WORKSPACE");

            string titleDataPath1 = "";

            JenkinsConsoleUtility.TryGetArgVar(out titleDataPath1, argsLc, "testTitleData");

            string titleDataPath2 = "";

            JenkinsConsoleUtility.TryGetArgVar(out titleDataPath2, argsLc, "PF_TEST_TITLE_DATA_JSON");

            // If testTitleData or PF_TEST_TITLE_DATA_JSON path is provided, save the path and try to load it
            HashSet <string> validFilepaths = new HashSet <string>();

            AddValidPath(validFilepaths, titleDataPath1, workspacePath);
            AddValidPath(validFilepaths, titleDataPath2, workspacePath);

            // Load the first file path that works
            foreach (var validFilepath in validFilepaths)
            {
                _LoadTestTitleData(validFilepath);
                if (testTitleData != null)
                {
                    return(testTitleData);
                }
            }

            JcuUtil.FancyWriteToConsole(ConsoleColor.Red, "ERROR: Could not load testTitleData.",
                                        ConsoleColor.Yellow, "WORKSPACE=", ConsoleColor.White, workspacePath,
                                        ConsoleColor.Yellow, "testTitleData=", ConsoleColor.White, titleDataPath1,
                                        ConsoleColor.Yellow, "PF_TEST_TITLE_DATA_JSON=", ConsoleColor.White, titleDataPath2,
                                        ConsoleColor.Yellow, "validFilepaths=", ConsoleColor.White, validFilepaths);

            return(null);
        }
        private static string GetTitleId(Dictionary <string, string> args)
        {
            // If titleId is provided directly, use it
            string temp;

            if (JenkinsConsoleUtility.TryGetArgVar(out temp, args, "titleId") && !string.IsNullOrEmpty(temp))
            {
                return(temp);
            }
            // If testTitleData path is provided, try to load the file
            if (JenkinsConsoleUtility.TryGetArgVar(out temp, args, "testTitleData") && !string.IsNullOrEmpty(temp))
            {
                return(GetTitleIdFromTestTitleData(temp));
            }
            // If PF_TEST_TITLE_DATA_JSON exists, get testTitleData path from it, and try to load the file
            temp = Environment.GetEnvironmentVariable("PF_TEST_TITLE_DATA_JSON");
            if (!string.IsNullOrEmpty(temp))
            {
                return(GetTitleIdFromTestTitleData(temp));
            }

            return(null);
        }
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            string destFile, workspacePath, varsWithSpaces;

            JenkinsConsoleUtility.TryGetArgVar(out destFile, argsLc, "destFile");
            JenkinsConsoleUtility.TryGetArgVar(out workspacePath, argsLc, "workspacePath");
            // Jenkins wants a file with spaces around the "=", but Bash wants a file without. This controls which format nuance to use
            JenkinsConsoleUtility.TryGetArgVar(out varsWithSpaces, argsLc, "varsWithSpaces");
            var sdkName   = JenkinsConsoleUtility.GetArgVar(argsLc, "sdkName");
            var sdkGenKey = GetSdkGenKey(sdkName);

            if (argsLc.ContainsKey("apispecpath"))
            {
                _apiSpecPath = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecPath");
            }
            else if (argsLc.ContainsKey("apispecgiturl"))
            {
                _apiSpecGitUrl = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecGitUrl");
            }
            else if (argsLc.ContainsKey("apispecpfurl"))
            {
                _apiSpecPfUrl = JenkinsConsoleUtility.GetArgVar(argsLc, "apiSpecPfUrl");
            }
            else
            {
                JcuUtil.FancyWriteToConsole("Api-Spec input not defined.  Please input one of: apiSpecPath, apiSpecGitUrl, apiSpecPfUrl");
                return(1);
            }

            var versionJson = GetApiJson("SdkManualNotes.json");
            var sdkNotes    = JsonWrapper.DeserializeObject <SdkManualNotes>(versionJson);

            if (!sdkNotes.sdkVersion.TryGetValue(sdkGenKey, out sdkVersionString))
            {
                JcuUtil.FancyWriteToConsole("SdkManualNotes.json does not contain: " + sdkGenKey);
                JcuUtil.FancyWriteToConsole("SdkManualNotes.json:\n" + versionJson);
                return(1);
            }

            var sdkPieces = sdkVersionString.Split('.');

            major = sdkPieces[0]; minor = sdkPieces[1]; date = sdkPieces[sdkPieces.Length - 1];
            set   = true;

            // Write this to a Jenkins environment variable file, if defined
            var space = " ";

            if (!string.IsNullOrEmpty(varsWithSpaces) && varsWithSpaces.ToLower() == "false")
            {
                space = "";
            }
            if (!string.IsNullOrEmpty(destFile))
            {
                using (var outputFile = new StreamWriter(Path.Combine(workspacePath, destFile)))
                {
                    outputFile.WriteLine("sdkVersion" + space + "=" + space + sdkVersionString);
                    outputFile.WriteLine("sdkDate" + space + "=" + space + date);
                }
            }
            else
            {
                JcuUtil.FancyWriteToConsole(System.ConsoleColor.Yellow, "WARNING: Output file not defined.");
            }
            JcuUtil.FancyWriteToConsole("sdkVersion" + space + "=" + space + sdkVersionString);
            JcuUtil.FancyWriteToConsole("sdkDate" + space + "=" + space + date);
            return(0);
        }
Esempio n. 9
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);
        }