Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            var taskName = JenkinsConsoleUtility.GetArgVar(argsLc, "taskName");

            List <Process> hitList = new List <Process>();

            hitList.AddRange(Process.GetProcessesByName(taskName));
            foreach (var eachProcess in hitList)
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Closing task: " + eachProcess.ProcessName, null, ConsoleColor.Yellow);
                eachProcess.CloseMainWindow(); // Gently close the target so they don't throw error codes
            }

            // Sleep for a while and wait for the programs to close safely
            var openCount = hitList.Count;

            for (var i = 0; i < TASK_KILL_DELAY_MS; i += TASK_KILL_SLEEP_MS)
            {
                Thread.Sleep(TASK_KILL_SLEEP_MS);
                openCount = 0;
                foreach (var eachProcess in hitList)
                {
                    if (!eachProcess.HasExited)
                    {
                        openCount += 1;
                    }
                }
                if (openCount == 0)
                {
                    break;
                }
            }

            // Time's up, close everything
            foreach (var eachProcess in hitList)
            {
                if (eachProcess.HasExited)
                {
                    continue; // Finished skip it
                }
                JenkinsConsoleUtility.FancyWriteToConsole("Killing task: " + eachProcess.ProcessName, null, ConsoleColor.Red);
                eachProcess.Kill(); // If it didn't close gently, then close it better.
            }

            if (hitList.Count == 0)
            {
                JenkinsConsoleUtility.FancyWriteToConsole("No tasks to kill: " + taskName, null, ConsoleColor.Red);
            }
            return(hitList.Count > 0 ? 0 : 1);
        }
Ejemplo n.º 3
0
        private string GetJsonInput(Dictionary <string, string> argsLc)
        {
            var calendarPath = JenkinsConsoleUtility.GetArgVar(argsLc, "calendarPath");

            if (!File.Exists(calendarPath))
            {
                var workspacePath = JenkinsConsoleUtility.GetArgVar(argsLc, "WORKSPACE");
                calendarPath = Path.Combine(workspacePath, "JenkinsSdkSetupScripts/JenkinsScripts/CalendarAlerts/calendarAlerts.json");
                if (!File.Exists(calendarPath))
                {
                    return(null);
                }
            }

            return(File.ReadAllText(calendarPath));
        }
Ejemplo n.º 4
0
        public int Execute(Dictionary <string, string> inputs)
        {
            string taskName;

            if (!inputs.TryGetValue("taskname", out taskName))
            {
                return(1);
            }

            var processes = Process.GetProcessesByName(taskName);

            foreach (var process in processes)
            {
                JenkinsConsoleUtility.FancyWriteToConsole("Killing task: " + process.ProcessName, null, ConsoleColor.Magenta);
                process.Kill();
            }

            return(processes.Length > 0 ? 0 : 1);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
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);
        }