public static bool RunTasks(DeploymentContext deploymentContext, DeploymentStatusUpdater statusUpdater)
        {
            IEnumerable <IDeploymentTask> tasks = GetTaskInstances(deploymentContext);
            Logger log = deploymentContext.CurrentLogger;

            foreach (IDeploymentTask task in tasks)
            {
                string taskName = task.GetType().Name;

                log.Info("Starting running task {0}", taskName);

                statusUpdater.UpdateStatus("Running task " + taskName);
                TaskResult result = task.RunTask(deploymentContext);

                switch (result.State)
                {
                case TaskResultState.Completed:
                    log.Info("Task {0} ran sucessfully", task);
                    break;

                case TaskResultState.CompletedWithError:
                    log.Error("Task {0} has errored: {1}", task, result.ErrorMessage);
                    break;

                case TaskResultState.Failed:
                    log.Fatal("Task {0} has failed. Deployment job will now stop. Error is: {1}", task, result.ErrorMessage);
                    return(false);
                }
            }

            // All tasks completed without failure, return true
            return(true);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Setup
            _defaultLogger = LogManager.GetLogger("Default");
            EnsureWorkingAreaExists();

            // Parse command line options
            CommandLineOptions options = new CommandLineOptions();

            Parser.Default.ParseArguments(args, options);

            Job currentJob = JobHelper.GetJob(options.JobId, _defaultLogger);

            if (currentJob == null)
            {
                ExitProgramWithError("Job not found");
            }

            // Intialise deployment context.
            DeploymentContext deploymentContext = DeploymentContextFactory.CreateContextForJob(currentJob);

            _statusUpdater = new DeploymentStatusUpdater(deploymentContext);

            // Checkout code from source control
            _statusUpdater.UpdateStatus(DeploymentStatuses.VscCheckout);
            GitProvider gitProvider     = new GitProvider(deploymentContext);
            bool        checkoutSuccess = gitProvider.Checkout();

            if (!checkoutSuccess)
            {
                ExitProgramWithError("Git checkout was unsuccessful.", currentJob);
            }

            // Load deployment conifguration
            bool configLoadSuccess = ConfigLoader.LoadConfigurationIntoContext(deploymentContext);

            if (!configLoadSuccess)
            {
                ExitProgramWithError("Could not load configuration", currentJob);
            }

            // Run Tasks
            bool taskRunResult = DeploymentTaskRunner.RunTasks(deploymentContext, _statusUpdater);

            if (taskRunResult)
            {
                _statusUpdater.Dispose();
                JobHelper.MarkJobAsComplete(currentJob);
            }
            else
            {
                ExitProgramWithError("Task did not complete.", currentJob);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Setup
            _defaultLogger = LogManager.GetLogger("Default");
            EnsureWorkingAreaExists();

            // Parse command line options
            CommandLineOptions options = new CommandLineOptions();
            Parser.Default.ParseArguments(args, options);

            Job currentJob = JobHelper.GetJob(options.JobId, _defaultLogger);
            if (currentJob == null) ExitProgramWithError("Job not found");

            // Intialise deployment context.
            DeploymentContext deploymentContext = DeploymentContextFactory.CreateContextForJob(currentJob);
            _statusUpdater = new DeploymentStatusUpdater(deploymentContext);

            // Checkout code from source control
            _statusUpdater.UpdateStatus(DeploymentStatuses.VscCheckout);
            GitProvider gitProvider = new GitProvider(deploymentContext);
            bool checkoutSuccess = gitProvider.Checkout();
            if (!checkoutSuccess) ExitProgramWithError("Git checkout was unsuccessful.", currentJob);

            // Load deployment conifguration
            bool configLoadSuccess = ConfigLoader.LoadConfigurationIntoContext(deploymentContext);
            if (!configLoadSuccess) ExitProgramWithError("Could not load configuration", currentJob);

            // Run Tasks
            bool taskRunResult = DeploymentTaskRunner.RunTasks(deploymentContext, _statusUpdater);

            if (taskRunResult)
            {
                _statusUpdater.Dispose();
                JobHelper.MarkJobAsComplete(currentJob);
            }
            else
            {
                ExitProgramWithError("Task did not complete.", currentJob);
            }
        }