Esempio n. 1
0
        public void Deploy(string deployer)
        {
            var         tracer     = _traceFactory.GetTracer();
            IDisposable deployStep = null;

            try
            {
                deployStep = tracer.Step("Deploy");
                PushInfo pushInfo = _serverRepository.GetPushInfo();

                // Something went wrong here since we weren't able to
                if (pushInfo == null || !pushInfo.Branch.IsMaster)
                {
                    if (pushInfo == null)
                    {
                        tracer.TraceWarning("Push info was null. Post receive hook didn't execute correctly");
                    }
                    else
                    {
                        tracer.Trace("Non-master branch deployed {0}", pushInfo.Branch.Name);

                        _globalLogger.Log(Resources.Log_NonMasterBranchPushed, pushInfo.Branch.Name);
                    }

                    ReportCompleted();
                    deployStep.Dispose();
                    return;
                }

                // Get the pushed branch's id
                string id = pushInfo.Branch.Id;
                // If nothing changed then do nothing
                if (IsActive(id))
                {
                    tracer.Trace("Deployment '{0}' already active", id);

                    _globalLogger.Log(Resources.Log_DeploymentAlreadyActive, id);

                    ReportCompleted();
                    deployStep.Dispose();
                    return;
                }

                ILogger logger = CreateAndPopulateStatusFile(tracer, id, deployer);

                using (tracer.Step("Update to " + pushInfo.Branch.Name))
                {
                    logger.Log(Resources.Log_UpdatingBranch, pushInfo.Branch.Name);

                    using (var progressWriter = new ProgressWriter())
                    {
                        progressWriter.Start();
                        // Update to the default branch
                        _serverRepository.Update();
                    }
                }

                Build(id, tracer, deployStep);
            }
            catch (Exception ex)
            {
                _globalLogger.Log(ex);

                tracer.TraceError(ex);

                if (deployStep != null)
                {
                    deployStep.Dispose();
                }

                ReportCompleted();
            }
        }