Ejemplo n.º 1
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            var testTitleData   = TestTitleDataLoader.Load(argsLc);
            var buildIdentifier = JenkinsConsoleUtility.GetArgVar(argsLc, "buildidentifier");
            var workspacePath   = JenkinsConsoleUtility.GetArgVar(argsLc, "workspacePath", Environment.GetEnvironmentVariable("TEMP"));
            var timeout         = TimeSpan.FromSeconds(int.Parse(JenkinsConsoleUtility.GetArgVar(argsLc, "timeout", "30")));

            verbose     = bool.Parse(JenkinsConsoleUtility.GetArgVar(argsLc, "verbose", "false"));
            _getRequest = new CsGetRequest {
                customId = buildIdentifier
            };

            JcuUtil.FancyWriteToConsole(ConsoleColor.Gray, "Begin CloudScriptListener");
            var returnCode = Login(testTitleData.titleId, buildIdentifier, testTitleData);

            if (returnCode != 0)
            {
                return(returnCode);
            }
            returnCode = WaitForTestResult(timeout, testTitleData);
            if (returnCode != 0)
            {
                return(returnCode);
            }
            JcuUtil.FancyWriteToConsole(ConsoleColor.Gray, "Test data found");
            returnCode = FetchTestResult(buildIdentifier, workspacePath, testTitleData);
            if (returnCode != 0)
            {
                return(returnCode);
            }
            JcuUtil.FancyWriteToConsole(ConsoleColor.Green, "Test data received");

            return(0);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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.º 5
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.º 6
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            var sdkName       = JenkinsConsoleUtility.GetArgVar(argsCased, "sdkName");
            var credsFilename = JenkinsConsoleUtility.GetArgVar(argsLc, "GITHUB_CREDENTIALS_FILE");

            if (!VersionVarWriter.set || !File.Exists(credsFilename))
            {
                return(1);
            }

            var credsJson = File.ReadAllText(credsFilename);
            var creds     = JsonWrapper.DeserializeObject <GitHubCredentials>(credsJson);

            try
            {
                var header = new ProductHeaderValue(ProgramHeader);
                var client = new GitHubClient(header);
                client.Credentials = new Credentials(creds.token);
                var releaseRequest = new GitHubReleaseRequest(sdkName, VersionVarWriter.major, VersionVarWriter.minor, VersionVarWriter.date);
                var result         = client.Repository.Release.Create(GitOwner, sdkName, releaseRequest).Result;
                if (!SeemsLegit(result, releaseRequest))
                {
                    return(1);
                }

                var sdkRepo = client.Repository.Get(GitOwner, sdkName).Result;
                JcuUtil.FancyWriteToConsole(ConsoleColor.Green, sdkRepo.CloneUrl);
            }
            catch (AggregateException agEx)
            {
                foreach (var e in agEx.InnerExceptions)
                {
                    JcuUtil.FancyWriteToConsole(ConsoleColor.Red, e.ToString());
                }
                return(1);
            }

            return(0);
        }
Ejemplo n.º 7
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            var taskNames = JenkinsConsoleUtility.GetArgVar(argsCased, "taskName");

            if (string.IsNullOrEmpty(taskNames))
            {
                return(1);
            }

            var hitList      = new List <Process>();
            var taskNameList = taskNames.Split(',');

            foreach (var eachTaskName in taskNameList)
            {
                var eachTaskNameTrim = eachTaskName.Trim();
                if (string.IsNullOrEmpty(eachTaskNameTrim))
                {
                    continue;
                }
                var eachHitList = Process.GetProcessesByName(eachTaskNameTrim);
                hitList.AddRange(eachHitList);
                foreach (var eachProcess in eachHitList)
                {
                    JcuUtil.FancyWriteToConsole(ConsoleColor.Yellow, "Closing task: " + eachProcess.ProcessName);
                    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
            for (var i = 0; i < TASK_KILL_DELAY_MS; i += TASK_KILL_SLEEP_MS)
            {
                Thread.Sleep(TASK_KILL_SLEEP_MS);
                var 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
                }
                JcuUtil.FancyWriteToConsole(ConsoleColor.Red, "Killing task: " + eachProcess.ProcessName);
                eachProcess.Kill(); // If it didn't close gently, then close it better.
            }

            if (hitList.Count == 0)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Red, "No tasks to kill: " + taskNames);
            }
            return(hitList.Count > 0 ? 0 : 1);
        }
Ejemplo n.º 8
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.º 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);
        }