public DeploymentResource DeployRelease(string releaseId, string environmentId, bool allowRedeploy = true)
        { 
            var deploymentResource = new DeploymentResource
            {
                ReleaseId = releaseId,
                EnvironmentId = environmentId,
                Comments = "Deployed with Kraken"
            };

            if (!allowRedeploy)
            {
                var checkDeploy = _repository.Deployments.FindOne(d => d.ReleaseId == releaseId && d.EnvironmentId == environmentId);
                
                if (checkDeploy != null)
                {
                    var task = _repository.Tasks.Get(checkDeploy.TaskId);
                    
                    // if the task hasn't finished successfully, then try to redeploy
                    if (task.FinishedSuccessfully)
                    {
                        var release = _repository.Releases.Get(checkDeploy.ReleaseId);

                        // if no modificatoins have been made to a successful deploy, assume it's a redeploy
                        if (release.LastModifiedOn <= checkDeploy.LastModifiedOn)
                        {
                            return null;
                        }
                    }
                }
            }

            return _repository.Deployments.Create(deploymentResource);
        }
        public void Run()
        {
            try
            {
                var deploymentResource = new DeploymentResource()
                {
                    EnvironmentId = "EnvironmentsId",
                    ReleaseId = instance.ReleaseId,
                    SpecificMachineIds = new ReferenceCollection(instance.Machine.Id),
                    Name = string.Format("Deploy To Aws {0} {1} {2}", instance.Ip, instance.Branch, instance.Release),
                    FormValues = new Dictionary<string, string>()
                    {

                    }
                };

                var deployment = client.repository.Deployments.Create(deploymentResource);

                instance.DeploymentId = deployment.Id;

                var limit = 45;

                while (limit > 0)
                {
                    var task = client.repository.Tasks.FindOne(t => t.Id == deployment.TaskId);
                    if (task.FinishedSuccessfully)
                    {
                        FinishedSuccessfully = true;
                    }

                    if (task.IsCompleted)
                    {
                        break;
                    }

                    Thread.Sleep(60000);
                    limit--;
                }
            }
            catch (Exception ex)
            {
                Error = ex.Message;
            }
        }
        public void LogDeploymentInfo(DeploymentResource deployment, Dictionary<string, string> environmentsById)
        {
            var nameOfDeploymentEnvironment = environmentsById[deployment.EnvironmentId];
            var taskId = deployment.Link("Task");
            var task = Repository.Tasks.Get(taskId);
            var release = Repository.Releases.Get(deployment.Link("Release"));

            var propertiesToLog = new List<string>();
            propertiesToLog.AddRange(FormatTaskPropertiesAsStrings(task));
            propertiesToLog.AddRange(FormatReleasePropertiesAsStrings(release));
            Log.InfoFormat(" - Environment: {0}", nameOfDeploymentEnvironment);
            foreach (var property in propertiesToLog)
            {
                if(property == "State: Failed")
                    Log.ErrorFormat("   {0}", property);
                else
                    Log.InfoFormat("   {0}", property);
            }
            Log.InfoFormat("");
        }
        public void SetUp()
        {
            deployReleaseCommand = new DeployReleaseCommand(RepositoryFactory, Log, FileSystem);

            var project = new ProjectResource();
            var release = new ReleaseResource { Version = "1.0.0" };
            var releases = new ResourceCollection<ReleaseResource>(new[] { release }, new LinkCollection());
            var deploymentPromotionTarget = new DeploymentPromotionTarget { Name = "TestEnvironment" };
            var promotionTargets = new List<DeploymentPromotionTarget> { deploymentPromotionTarget };
            var deploymentTemplate = new DeploymentTemplateResource { PromoteTo = promotionTargets };
            var deploymentPreviewResource = new DeploymentPreviewResource { StepsToExecute = new List<DeploymentTemplateStep>() };
            var deployment = new DeploymentResource { TaskId = "1" };
            taskResource = new TaskResource();

            Repository.Projects.FindByName(ProjectName).Returns(project);
            Repository.Projects.GetReleases(project).Returns(releases);
            Repository.Releases.GetPreview(deploymentPromotionTarget).Returns(deploymentPreviewResource);
            Repository.Releases.GetTemplate(release).Returns(deploymentTemplate);
            Repository.Deployments.Create(Arg.Any<DeploymentResource>()).Returns(deployment);
            Repository.Tasks.Get(deployment.TaskId).Returns(taskResource);
        }
Exemplo n.º 5
0
        public DeploymentResource DeployRelease(string releaseId, string environmentId, bool forceRedeploy)
        {
            var deploymentResource = new DeploymentResource
            {
                ReleaseId = releaseId,
                EnvironmentId = environmentId,
                Comments = "Deployed with Kraken"
            };

            if (!forceRedeploy)
            {
                var release = _octopusRepository.Releases.Get(releaseId);
                DeploymentResource checkDeploy;
                try
                {
                    checkDeploy = _octopusRepository.Releases.GetDeployments(release).Items.FirstOrDefault(d => d.EnvironmentId == environmentId);
                }
                catch (OctopusResourceNotFoundException)
                {
                    checkDeploy = null;
                }

                if (checkDeploy != null && checkDeploy.ReleaseId == releaseId)
                {
                    var task = _octopusRepository.Tasks.Get(checkDeploy.TaskId);

                    // if the task hasn't completed, don't queue up another deploy
                    if (!task.IsCompleted)
                    {
                        return null;
                    }

                    // if the task has finished successfully, only redeploy if there have been modifications made to the release since the deploy
                    if (task.FinishedSuccessfully)
                    {

                        // if no modifications have been made to a successful deploy since its creation, assume it's a redeploy
                        if (release.LastModifiedOn <= checkDeploy.Created)
                        {
                            return null;
                        }
                    }
                }
            }

            return _octopusRepository.Deployments.Create(deploymentResource);
        }
Exemplo n.º 6
0
 public DeploymentResource CreateDeployment(string machineId, string releaseId, string environmentId, string comment)
 {
     var deploymentResource = new DeploymentResource
     {                
         ReleaseId = releaseId,
         EnvironmentId = environmentId,
         SpecificMachineIds = new ReferenceCollection(new[] { machineId }),
         Comments = comment
     };
     
     var deployment = Repository.Deployments.Create(deploymentResource);
     
     return deployment;
 }