예제 #1
0
        private async Task DeployAsync(IUiLogger uiLogger, Dictionary <ProjectDeployment, TaskDetails> failedProjects, Dictionary <string, TaskDetails> taskRegister, Dictionary <string, ProjectDeployment> projectRegister)
        {
            var done       = false;
            int totalCount = taskRegister.Count();

            while (!done)
            {
                var tasks = await this.helper.GetDeploymentTasks(0, 100);

                foreach (var currentTask in taskRegister.ToList())
                {
                    var found = tasks.FirstOrDefault(t => t.TaskId == currentTask.Key);
                    if (found == null)
                    {
                        uiLogger.CleanCurrentLine();
                        uiLogger.WriteLine($"Couldn't find {currentTask.Key} in the tasks list?");
                        taskRegister.Remove(currentTask.Key);
                    }
                    else
                    {
                        if (found.State == Models.TaskStatus.Done)
                        {
                            var finishedTask = await this.helper.GetTaskDetails(found.TaskId);

                            var project = projectRegister[currentTask.Key];
                            uiLogger.CleanCurrentLine();
                            uiLogger.WriteLine($"{project.ProjectName} deployed successfully");
                            taskRegister.Remove(currentTask.Key);
                        }
                        else if (found.State == Models.TaskStatus.Failed)
                        {
                            var finishedTask = await this.helper.GetTaskDetails(found.TaskId);

                            var project = projectRegister[currentTask.Key];
                            uiLogger.CleanCurrentLine();
                            uiLogger.WriteLine($"{currentTask.Key} failed to deploy with error: {found.ErrorMessage}");
                            failedProjects.Add(project, finishedTask);
                            taskRegister.Remove(currentTask.Key);
                        }
                    }
                }

                if (taskRegister.Count == 0)
                {
                    done = true;
                }

                uiLogger.WriteProgress(totalCount - taskRegister.Count, totalCount, $"Deploying the requested projects ({totalCount - taskRegister.Count} of {totalCount} done)...");

                await Task.Delay(3000);
            }
            uiLogger.CleanCurrentLine();
        }
예제 #2
0
 private static void WriteStatus(IUiLogger uiLogger, TaskDetails taskDeets)
 {
     if (taskDeets.State != Models.TaskStatus.Queued)
     {
         if (taskDeets.PercentageComplete < 100)
         {
             uiLogger.WriteLine("Current status: " + taskDeets.State + " Percentage: " +
                                taskDeets.PercentageComplete + " estimated time remaining: " +
                                taskDeets.TimeLeft);
         }
     }
     else
     {
         uiLogger.WriteLine("Currently queued... waiting");
     }
 }
예제 #3
0
        private async Task ProcessEnvironmentDeployment(EnvironmentDeployment deployment, bool suppressMessages,
                                                        IUiLogger uiLogger)
        {
            uiLogger.WriteLine("Starting deployment!");
            var failedProjects = new Dictionary <ProjectDeployment, TaskDetails>();

            var taskRegister    = new Dictionary <string, TaskDetails>();
            var projectRegister = new Dictionary <string, ProjectDeployment>();

            foreach (var project in deployment.ProjectDeployments)
            {
                Release result;
                if (string.IsNullOrEmpty(project.ReleaseId))
                {
                    uiLogger.WriteLine("Creating a release for project " + project.ProjectName + "... ");
                    result = await helper.CreateRelease(project, deployment.FallbackToDefaultChannel);
                }
                else
                {
                    uiLogger.WriteLine("Fetching existing release for project " + project.ProjectName + "... ");
                    result = await helper.GetRelease(project.ReleaseId);
                }

                uiLogger.WriteLine("Creating deployment task for " + result.Version + " to " + deployment.EnvironmentName);
                var deployResult = await helper.CreateDeploymentTask(project, deployment.EnvironmentId, result.Id);

                uiLogger.WriteLine("Created");

                var taskDeets = await helper.GetTaskDetails(deployResult.TaskId);

                //taskDeets = await StartDeployment(uiLogger, taskDeets, !deployment.DeployAsync);
                if (deployment.DeployAsync)
                {
                    taskRegister.Add(taskDeets.TaskId, taskDeets);
                    projectRegister.Add(taskDeets.TaskId, project);
                }
                else
                {
                    if (taskDeets.State == Models.TaskStatus.Failed)
                    {
                        uiLogger.WriteLine("Failed deploying " + project.ProjectName);
                        failedProjects.Add(project, taskDeets);
                    }
                    uiLogger.WriteLine("Deployed!");
                    uiLogger.WriteLine("Full Log: " + System.Environment.NewLine +
                                       await this.helper.GetTaskRawLog(taskDeets.TaskId));
                    taskDeets = await helper.GetTaskDetails(deployResult.TaskId);
                }
            }


            // This needs serious improvement.
            if (deployment.DeployAsync)
            {
                await DeployAsync(uiLogger, failedProjects, taskRegister, projectRegister);
            }

            uiLogger.WriteLine("Done deploying!");
            if (failedProjects.Any())
            {
                uiLogger.WriteLine("Some projects didn't deploy successfully: ");
                foreach (var failure in failedProjects)
                {
                    var link = string.Empty;
                    if (failure.Value.Links != null)
                    {
                        if (failure.Value.Links.ContainsKey("Web"))
                        {
                            link = configuration.OctopusUrl + failure.Value.Links["Web"];
                        }
                    }
                    uiLogger.WriteLine(failure.Key.ProjectName + ": " + link);
                }
            }
            if (!suppressMessages)
            {
                uiLogger.WriteLine("Done deploying!" +
                                   (failedProjects.Any() ? " There were failures though. Check the log." : string.Empty));
            }
        }