Exemple #1
0
        public void Deploy(IRepository repository, string deployer)
        {
            var tracer = _traceFactory.GetTracer();
            IDisposable deployStep = null;
            var deploymentRepository = new DeploymentRepository(repository);
            try
            {
                deployStep = tracer.Step("Deploy");
                ReceiveInfo receiveInfo = deploymentRepository.GetReceiveInfo();

                string targetBranch = _settings.GetValue(SettingsKeys.Branch);

                tracer.Trace("Deploying branch '{0}'", targetBranch);

                // Something went wrong here since we weren't able to deploy if receiveInfo is null
                if (receiveInfo == null || !targetBranch.Equals(receiveInfo.Branch.Name, StringComparison.OrdinalIgnoreCase))
                {
                    if (receiveInfo == null)
                    {
                        tracer.TraceWarning("Push info was null. Post receive hook didn't execute correctly");
                    }
                    else
                    {
                        tracer.Trace("Unexpected branch deployed '{0}'.", receiveInfo.Branch.Name);

                        _globalLogger.Log(Resources.Log_UnexpectedBranchPushed, receiveInfo.Branch.Name, targetBranch);
                    }

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

                // Get the pushed branch's id
                string id = receiveInfo.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;
                }

                ChangeSet changeSet = deploymentRepository.GetChangeSet(id);
                ILogger logger = GetOrCreateStatusFile(changeSet, tracer, deployer);
                logger.Log(Resources.Log_NewDeploymentReceived);

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

                    using (var progressWriter = new ProgressWriter())
                    {
                        progressWriter.Start();

                        // Update to the target branch
                        deploymentRepository.Update(targetBranch);
                    }
                }

                using (tracer.Step("Update submodules"))
                {
                    logger.Log(Resources.Log_UpdatingSubmodules);

                    using (var progressWriter = new ProgressWriter())
                    {
                        progressWriter.Start();

                        deploymentRepository.UpdateSubmodules();
                    }
                }

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

                tracer.TraceError(ex);

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

                ReportCompleted();
            }
        }
        public void Deploy(IRepository repository, ChangeSet changeSet, string deployer, bool clean)
        {
            ITracer tracer = _traceFactory.GetTracer();
            IDisposable deployStep = null;
            ILogger innerLogger = null;
            string targetBranch = null;
            var deploymentRepository = new DeploymentRepository(repository);

            // If we don't get a changeset, find out what branch we should be deploying and get the commit ID from it
            if (changeSet == null)
            {
                targetBranch = _settings.GetBranch();

                changeSet = deploymentRepository.GetChangeSet(targetBranch);
            }

            string id = changeSet.Id;
            IDeploymentStatusFile statusFile = null;
            try
            {
                deployStep = tracer.Step("DeploymentManager.Deploy(id)");

                // Remove the old log file for this deployment id
                string logPath = GetLogPath(id);
                FileSystemHelpers.DeleteFileSafe(logPath);

                statusFile = GetOrCreateStatusFile(changeSet, tracer, deployer);
                statusFile.MarkPending();

                ILogger logger = GetLogger(changeSet.Id);

                using (tracer.Step("Updating to specific changeset"))
                {
                    innerLogger = logger.Log(Resources.Log_UpdatingBranch, targetBranch ?? id);

                    using (var writer = new ProgressWriter())
                    {
                        // Update to the the specific changeset
                        deploymentRepository.Update(id);
                    }
                }

                using (tracer.Step("Updating submodules"))
                {
                    innerLogger = logger.Log(Resources.Log_UpdatingSubmodules);

                    deploymentRepository.UpdateSubmodules();
                }

                if (clean)
                {
                    tracer.Trace("Cleaning {0} repository", repository.RepositoryType);

                    innerLogger = logger.Log(Resources.Log_CleaningRepository, repository.RepositoryType);

                    deploymentRepository.Clean();
                }

                // set to null as Build() below takes over logging
                innerLogger = null;

                // Perform the build deployment of this changeset
                Build(id, tracer, deployStep);
            }
            catch (Exception ex)
            {
                if (innerLogger != null)
                {
                    innerLogger.Log(ex);
                }

                if (statusFile != null)
                {
                    statusFile.MarkFailed();
                }

                tracer.TraceError(ex);

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

                throw;
            }
        }
Exemple #3
0
        public void Deploy(IRepository repository, ChangeSet changeSet, string deployer, bool clean)
        {
            ITracer tracer = _traceFactory.GetTracer();
            IDisposable deployStep = null;
            var deploymentRepository = new DeploymentRepository(repository);

            // If we don't get a changeset, find out what branch we should be deploying and update the repo to it
            if (changeSet == null)
            {
                string targetBranch = _settings.GetValue(SettingsKeys.Branch);
                deploymentRepository.Update(targetBranch);

                changeSet = deploymentRepository.GetChangeSet(repository.CurrentId);
            }

            string id = changeSet.Id;
            try
            {
                deployStep = tracer.Step("DeploymentManager.Deploy(id)");

                // Remove the old log file for this deployment id
                string logPath = GetLogPath(id);
                FileSystemHelpers.DeleteFileSafe(logPath);

                ILogger logger = GetOrCreateStatusFile(changeSet, tracer, deployer);

                using (tracer.Step("Updating to specific changeset"))
                {
                    // Update to the the specific changeset
                    deploymentRepository.Update(id);
                }

                using (tracer.Step("Updating submodules"))
                {

                    deploymentRepository.UpdateSubmodules();
                }

                if (clean)
                {
                    tracer.Trace("Cleaning {0} repository", repository.RepositoryType);

                    logger.Log(Resources.Log_CleaningRepository, repository.RepositoryType);

                    deploymentRepository.Clean();
                }

                // Perform the build deployment of this changeset
                Build(id, tracer, deployStep);
            }
            catch (Exception ex)
            {
                tracer.TraceError(ex);

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

                throw;
            }
        }