Ejemplo n.º 1
0
        public static DeploymentResource CreateDeployment(string projectName, string releaseVersion,
                                                          SingleProjectDeploymentSettings settings)
        {
            var project = new OctoProject(projectName);
            var release = project.GetReleaseByVersion(releaseVersion);

            return(CreateDeployment(project, release, settings));
        }
Ejemplo n.º 2
0
        public static DeploymentResource CreateDeployment(OctoProject project, ReleaseResource release,
                                                          string targetEnvironmentName)
        {
            var settings = new SingleProjectDeploymentSettings {
                TargetEnvironmentName = targetEnvironmentName
            };

            return(CreateDeployment(project, release, settings));
        }
Ejemplo n.º 3
0
        public static DeploymentResource PromoteRelease(string projectName, string releaseVersion,
                                                        SingleReleasePromotingSettings settings)
        {
            var project   = new OctoProject(projectName);
            var sourceEnv = WebClient.GetWebClientRef().GetEnvironmentByName(settings.SourceEnvironmentName);

            settings.Release = releaseVersion is null ? null : project.GetReleaseByVersion(releaseVersion);
            return(PromoteRelease(project, sourceEnv, settings));
        }
Ejemplo n.º 4
0
        public static DeploymentResource CreateDeployment(string projectName, string releaseVersion,
                                                          string targetEnvironmentName)
        {
            var project  = new OctoProject(projectName);
            var release  = project.GetReleaseByVersion(releaseVersion);
            var settings = new SingleProjectDeploymentSettings {
                TargetEnvironmentName = targetEnvironmentName
            };

            return(CreateDeployment(project, release, settings));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Promote Release from one environment to another. If the releaseVersion is not specified.
 /// The release has the latest deployment at sourceEnv will be chosen to deploy to the targetEnv.
 /// Skip creating the deployment if there is no release at the input Env
 /// </summary>
 /// <param name="project"></param>
 /// <param name="sourceEnv"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static DeploymentResource PromoteRelease(OctoProject project, EnvironmentResource sourceEnv,
                                                 SingleReleasePromotingSettings settings)
 {
     if (settings.Release == null)
     {
         var releaseRepo  = WebClient.GetWebClientRef().GetReleaseRepo();
         var sourceDeploy = project.GetDeployment(sourceEnv);
         settings.Release = sourceDeploy == null ? null : releaseRepo.Get(sourceDeploy.ReleaseId);
     }
     return(settings.Release == null ? null : CreateDeployment(project, settings.Release,
                                                               new SingleProjectDeploymentSettings(settings)));
 }
Ejemplo n.º 6
0
        public static DeploymentResource CreateDeployment(OctoProject project, ReleaseResource release,
                                                          SingleProjectDeploymentSettings settings)
        {
            var client = WebClient.GetWebClientRef();

            // Check if the project has been disabled
            if (project.IsDisabled() || settings.Force || release == null)
            {
                return(null);
            }

            Console.WriteLine($"Starting to Create Deployment for {project.ProjectName}");
            // Update the variable set
            if (settings.UpdateVariableSetNow)
            {
                Console.WriteLine($"Update Release {release.Version} variables now");

                release = client.GetReleaseRepo().SnapshotVariables(release);
            }

            if (settings.NeedRebootAfterDeployment)
            {
                Console.WriteLine("Deployment Target Server(s) Will Reboot After Deployment");
                settings.WaitingForFinish = true;
            }

            //creating the deployment object
            var deployment = new DeploymentResource
            {
                ReleaseId          = release.Id,
                ProjectId          = project.GetProjectId(),
                EnvironmentId      = client.GetEnvironmentIdByName(settings.TargetEnvironmentName),
                SpecificMachineIds = settings.ConvertMachineNames(),
                Comments           = settings.Comments,
                UseGuidedFailure   = settings.UseGuidedFailure,
                SkipActions        = settings.ConvertSkipSteps()
            };

            // Schedule the deployment if deployment time is greater than now
            if (settings.DeployAt > DateTime.Now)
            {
                deployment.QueueTime      = new DateTimeOffset(settings.DeployAt);
                settings.WaitingForFinish = false;
            }

            deployment = client.GetDeploymentRepo().Create(deployment);

            Console.WriteLine($"{project.ProjectName} will {deployment.Name}");

            var task = new OctoTask(deployment);

            task.PrintCurrentState(settings.WaitingForFinish);

            if (!settings.NeedRebootAfterDeployment)
            {
                return(deployment);
            }
            var rolesNameList = project.GetTargetRolesNameList();
            var machines      = OctoMachines.GetMachinesByEnvName(settings.TargetEnvironmentName, rolesNameList);

            machines.RestartServer();

            return(deployment);
        }
Ejemplo n.º 7
0
        public static ReleaseResource CreateRelease(string projectName, CreateReleaseSettings settings)
        {
            var client        = WebClient.GetWebClientRef();
            var project       = new OctoProject(projectName);
            var targetChannel = project.GetChannelByName(settings.ReleaseChannel);
            var process       = client.GetDeploymentProcessRepo().Get(project.GetDeploymentProcessId());
            var template      = client.GetDeploymentProcessRepo().GetTemplate(process, targetChannel);

            if (project.IsDisabled() && !settings.IgnoreChannelRules)
            {
                return(null);
            }

            // If no version set up in the createReleaseSettings, Create a version number by using template
            if (string.IsNullOrEmpty(settings.ReleaseVersion))
            {
                settings.ReleaseVersion = template.NextVersionIncrement;
            }

            // Initialize the new release with basic settings
            var newRelease = new ReleaseResource {
                ProjectId    = project.GetProjectId(),
                ChannelId    = targetChannel.Id,
                Version      = settings.ReleaseVersion,
                ReleaseNotes = settings.ReleaseNotes
            };

            Console.WriteLine("Create Release Version: {0} of {1} at {2}", settings.ReleaseVersion, projectName, targetChannel.Name);

            var feedRepo = client.GetFeedRepo();

            // Select packages
            foreach (var package in template.Packages)
            {
                var actionName      = package.ActionName;
                var packageId       = package.PackageId;
                var feedId          = package.FeedId;
                var selectedPackage = new SelectedPackage()
                {
                    ActionName = actionName
                };
                // If the package version is not specify, choose the one with the latest version at the current channel
                if (settings.Packages is null)
                {
                    var feed = feedRepo.Get(feedId);
                    var latestPackageVersion = feedRepo.GetVersions(feed, new[] { packageId }).FirstOrDefault();

                    // When the package needed doesn't exist on Octopus repo
                    if (latestPackageVersion is null)
                    {
                        throw new PackageNotFoundException(
                                  $"Please upload package: {packageId} to Octopus repo");
                    }
                    selectedPackage.Version = latestPackageVersion.Version;
                }
                else
                {
                    selectedPackage.Version = settings.Packages[package.PackageId];
                }

                Console.WriteLine("{0}: {1} {2}", actionName, packageId, selectedPackage.Version);

                newRelease.SelectedPackages.Add(selectedPackage);
            }

            return(client.GetReleaseRepo().Create(newRelease, settings.IgnoreChannelRules));
        }