Beispiel #1
0
        public override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName))
            {
                throw new CommandException("Please specify a project name using the parameter: --project=XYZ");
            }

            Log.Debug("Finding project: " + ProjectName);
            var project = Session.GetProject(ProjectName);

            Log.Debug("Finding environments...");
            var environments = Session.FindEnvironments(DeployToEnvironmentNames);

            Log.Debug("Finding steps for project...");
            var steps = Session.FindStepsForProject(project);

            var plan = new ReleasePlan(steps, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    Log.Debug("  - Finding latest NuGet package for step: " + unresolved.StepName);
                    unresolved.SetVersionFromLatest(Session.GetLatestPackageForStep(unresolved.Step).NuGetPackageVersion);
                }
            }

            var versionNumber = VersionNumber;

            if (string.IsNullOrWhiteSpace(versionNumber))
            {
                Log.Warn("A --version parameter was not specified, so a version number was automatically selected based on the highest package version.");
                versionNumber = plan.GetHighestVersionNumber();
            }

            Log.Info("Release plan for release:    " + versionNumber);
            Log.Info("Steps: ");
            Log.Info(plan.FormatAsTable());

            Log.Debug("Creating release...");
            var release = Session.CreateRelease(project, plan.GetSelections(), versionNumber, ReleaseNotes);

            Log.Info("Release created successfully!");

            Log.ServiceMessage("setParameter", new { name = "octo.releaseNumber", value = release.Version });

            if (environments == null || environments.Count <= 0)
            {
                return;
            }
            var linksToDeploymentTasks = Session.GetDeployments(release, environments, Force, ForcePackageDownload, Log).ToList();

            if (WaitForDeployment)
            {
                deploymentWatcher.WaitForDeploymentsToFinish(Session, linksToDeploymentTasks, DeploymentTimeout, DeploymentStatusCheckSleepCycle);
            }
        }
        protected override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName)) throw new CommandException("Please specify a project name using the parameter: --project=XYZ");

            Log.Debug("Finding project: " + ProjectName);
            var project = Repository.Projects.FindByName(ProjectName);
            if (project == null)
                throw new CouldNotFindException("a project named", ProjectName);

            var channel = default(ChannelResource);
            if (!string.IsNullOrWhiteSpace(ChannelName))
            {
                Log.Debug("Finding channel");
                var channels = Repository.Projects.GetChannels(project).Items;
                channel = channels.SingleOrDefault(c => string.Equals(c.Name, ChannelName, StringComparison.Ordinal));
                if (channel == null)
                    throw new CouldNotFindException("a channel named", ChannelName);
            }

            Log.Debug("Finding deployment process for project: " + ProjectName);
            var deploymentProcess = Repository.DeploymentProcesses.Get(project.DeploymentProcessId);

            Log.Debug("Finding release template...");
            var releaseTemplate = Repository.DeploymentProcesses.GetTemplate(deploymentProcess, channel);

            var plan = new ReleasePlan(releaseTemplate, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    if (!unresolved.IsResolveable)
                    {
                        Log.ErrorFormat("The version number for step '{0}' cannot be automatically resolved because the feed or package ID is dynamic.", unresolved.StepName);
                        continue;
                    }

                    if (!string.IsNullOrEmpty(VersionPrerelease))
                        Log.DebugFormat("Finding latest NuGet package with pre-release '{1}' for step: {0}", unresolved.StepName, VersionPrerelease);
                    else
                        Log.DebugFormat("Finding latest NuGet package for step: {0}", unresolved.StepName);

                    var feed = Repository.Feeds.Get(unresolved.NuGetFeedId);
                    if (feed == null)
                        throw new CommandException(string.Format("Could not find a feed with ID {0}, which is used by step: " + unresolved.StepName, unresolved.NuGetFeedId));

                    IEnumerable<PackageResource> packages;
                    if (!string.IsNullOrWhiteSpace(VersionPrerelease))
                        packages = Repository.Client.Get<List<PackageResource>>(feed.Link("SearchTemplate"), new { packageId = unresolved.PackageId, partialMatch = true }).Where(p => p.NuGetPackageId == unresolved.PackageId && p.Version.EndsWith("-" + VersionPrerelease));
                    else
                        packages = Repository.Client.Get<List<PackageResource>>(feed.Link("VersionsTemplate"), new { packageIds = new[] { unresolved.PackageId } });
                     var version = packages.FirstOrDefault();

                    if (version == null)
                    {
                        Log.ErrorFormat("Could not find any packages with ID '{0}' in the feed '{1}'", unresolved.PackageId, feed.FeedUri);
                    }
                    else
                    {
                        unresolved.SetVersionFromLatest(version.Version);
                    }
                }
            }

            string versionNumber;
            if (!string.IsNullOrWhiteSpace(VersionNumber))
            {
                Log.Debug("Using version number provided on command-line.");
                versionNumber = VersionNumber;
            }
            else if (!string.IsNullOrWhiteSpace(releaseTemplate.NextVersionIncrement))
            {
                Log.Debug("Using version number from release template.");
                versionNumber = releaseTemplate.NextVersionIncrement;
            }
            else if (!string.IsNullOrWhiteSpace(releaseTemplate.VersioningPackageStepName))
            {
                Log.Debug("Using version number from package step.");
                versionNumber = plan.GetActionVersionNumber(releaseTemplate.VersioningPackageStepName);
            }
            else
            {
                throw new CommandException("A version number was not specified and could not be automatically selected.");
            }

            if (plan.Steps.Count > 0)
            {
                Log.Info("Release plan for release:    " + versionNumber);
                Log.Info("Steps: ");
                Log.Info(plan.FormatAsTable());
            }

            if (plan.HasUnresolvedSteps())
            {
                throw new CommandException("Package versions could not be resolved for one or more of the package steps in this release. See the errors above for details. Either ensure the latest version of the package can be automatically resolved, or set the version to use specifically by using the --package argument.");
            }

            Log.Debug("Creating release...");

            if (IgnoreIfAlreadyExists)
            {
                try
                {
                    var found = Repository.Projects.GetReleaseByVersion(project, versionNumber);
                    if (found != null)
                    {
                        Log.Info("A release with the number " + versionNumber + " already exists.");
                        return;
                    }
                }
                catch (OctopusResourceNotFoundException)
                {
                    // Expected
                }
            }

            var release = Repository.Releases.Create(new ReleaseResource(versionNumber, project.Id, channel?.Id)
            {
                ReleaseNotes = ReleaseNotes,
                SelectedPackages = plan.GetSelections()
            }, Force);
            Log.Info("Release " + release.Version + " created successfully!");

            Log.ServiceMessage("setParameter", new {name = "octo.releaseNumber", value = release.Version});

            DeployRelease(project, release, DeployToEnvironmentNames);
        }
        protected override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName)) throw new CommandException("Please specify a project name using the parameter: --project=XYZ");

            Log.Debug("Finding project: " + ProjectName);
            var project = Session.GetProject(ProjectName);

            Log.Debug("Finding environments...");
            var environments = Session.FindEnvironments(DeployToEnvironmentNames);

            Log.Debug("Finding steps for project...");
            var steps = Session.FindStepsForProject(project);

            var plan = new ReleasePlan(steps, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    Log.Debug("  - Finding latest NuGet package for step: " + unresolved.StepName);
                    unresolved.SetVersionFromLatest(Session.GetLatestPackageForStep(unresolved.Step).NuGetPackageVersion);
                }
            }

            var versionNumber = VersionNumber;
            if (string.IsNullOrWhiteSpace(versionNumber))
            {
                Log.Warn("A --version parameter was not specified, so a version number was automatically selected based on the highest package version.");
                versionNumber = plan.GetHighestVersionNumber();
            }

            Log.Info("Release plan for release:    " + versionNumber);
            Log.Info("Steps: ");
            Log.Info(plan.FormatAsTable());

            Log.Debug("Creating release...");
            var release = Session.CreateRelease(project, plan.GetSelections(), versionNumber, ReleaseNotes);
            Log.Info("Release created successfully!");

            Log.ServiceMessage("setParameter", new { name = "octo.releaseNumber", value = release.Version });

            if (environments == null || environments.Count <= 0) return;
            var linksToDeploymentTasks = Session.GetDeployments(release, environments, Force, ForcePackageDownload, Log).ToList();

            if (WaitForDeployment)
            {
                deploymentWatcher.WaitForDeploymentsToFinish(Session, linksToDeploymentTasks, DeploymentTimeout, DeploymentStatusCheckSleepCycle);
            }
        }
        protected override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName))
            {
                throw new CommandException("Please specify a project name using the parameter: --project=XYZ");
            }

            Log.Debug("Finding project: " + ProjectName);
            var project = Repository.Projects.FindByName(ProjectName);

            if (project == null)
            {
                throw new CouldNotFindException("a project named", ProjectName);
            }

            var channel = default(ChannelResource);

            if (!string.IsNullOrWhiteSpace(ChannelName))
            {
                Log.Debug("Finding channel");
                var channels = Repository.Projects.GetChannels(project).Items;
                channel = channels.SingleOrDefault(c => string.Equals(c.Name, ChannelName, StringComparison.Ordinal));
                if (channel == null)
                {
                    throw new CouldNotFindException("a channel named", ChannelName);
                }
            }


            Log.Debug("Finding deployment process for project: " + ProjectName);
            var deploymentProcess = Repository.DeploymentProcesses.Get(project.DeploymentProcessId);

            Log.Debug("Finding release template...");
            var releaseTemplate = Repository.DeploymentProcesses.GetTemplate(deploymentProcess, channel);

            var plan = new ReleasePlan(releaseTemplate, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    if (!unresolved.IsResolveable)
                    {
                        Log.ErrorFormat("The version number for step '{0}' cannot be automatically resolved because the feed or package ID is dynamic.", unresolved.StepName);
                        continue;
                    }

                    if (!string.IsNullOrEmpty(VersionPrerelease))
                    {
                        Log.DebugFormat("Finding latest NuGet package with pre-release '{1}' for step: {0}", unresolved.StepName, VersionPrerelease);
                    }
                    else
                    {
                        Log.DebugFormat("Finding latest NuGet package for step: {0}", unresolved.StepName);
                    }

                    var feed = Repository.Feeds.Get(unresolved.NuGetFeedId);
                    if (feed == null)
                    {
                        throw new CommandException(string.Format("Could not find a feed with ID {0}, which is used by step: " + unresolved.StepName, unresolved.NuGetFeedId));
                    }

                    IEnumerable <PackageResource> packages;
                    if (!string.IsNullOrWhiteSpace(VersionPrerelease))
                    {
                        packages = Repository.Client.Get <List <PackageResource> >(feed.Link("SearchTemplate"), new { packageId = unresolved.PackageId, partialMatch = true }).Where(p => p.NuGetPackageId == unresolved.PackageId && p.Version.EndsWith("-" + VersionPrerelease));
                    }
                    else
                    {
                        packages = Repository.Client.Get <List <PackageResource> >(feed.Link("VersionsTemplate"), new { packageIds = new[] { unresolved.PackageId } });
                    }
                    var version = packages.FirstOrDefault();

                    if (version == null)
                    {
                        Log.ErrorFormat("Could not find any packages with ID '{0}' in the feed '{1}'", unresolved.PackageId, feed.FeedUri);
                    }
                    else
                    {
                        unresolved.SetVersionFromLatest(version.Version);
                    }
                }
            }

            string versionNumber;

            if (!string.IsNullOrWhiteSpace(VersionNumber))
            {
                Log.Debug("Using version number provided on command-line.");
                versionNumber = VersionNumber;
            }
            else if (!string.IsNullOrWhiteSpace(releaseTemplate.NextVersionIncrement))
            {
                Log.Debug("Using version number from release template.");
                versionNumber = releaseTemplate.NextVersionIncrement;
            }
            else if (!string.IsNullOrWhiteSpace(releaseTemplate.VersioningPackageStepName))
            {
                Log.Debug("Using version number from package step.");
                versionNumber = plan.GetActionVersionNumber(releaseTemplate.VersioningPackageStepName);
            }
            else
            {
                throw new CommandException("A version number was not specified and could not be automatically selected.");
            }

            if (plan.Steps.Count > 0)
            {
                Log.Info("Release plan for release:    " + versionNumber);
                Log.Info("Steps: ");
                Log.Info(plan.FormatAsTable());
            }

            if (plan.HasUnresolvedSteps())
            {
                throw new CommandException("Package versions could not be resolved for one or more of the package steps in this release. See the errors above for details. Either ensure the latest version of the package can be automatically resolved, or set the version to use specifically by using the --package argument.");
            }

            Log.Debug("Creating release...");

            if (IgnoreIfAlreadyExists)
            {
                try
                {
                    var found = Repository.Projects.GetReleaseByVersion(project, versionNumber);
                    if (found != null)
                    {
                        Log.Info("A release with the number " + versionNumber + " already exists.");
                        return;
                    }
                }
                catch (OctopusResourceNotFoundException)
                {
                    // Expected
                }
            }

            var release = Repository.Releases.Create(new ReleaseResource(versionNumber, project.Id, channel?.Id)
            {
                ReleaseNotes     = ReleaseNotes,
                SelectedPackages = plan.GetSelections()
            }, Force);

            Log.Info("Release " + release.Version + " created successfully!");

            Log.ServiceMessage("setParameter", new { name = "octo.releaseNumber", value = release.Version });

            DeployRelease(project, release, DeployToEnvironmentNames);
        }
        protected override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName)) throw new CommandException("Please specify a project name using the parameter: --project=XYZ");

            Log.Debug("Finding project: " + ProjectName);
            var project = Repository.Projects.FindByName(ProjectName);
            if (project == null)
                throw new CommandException("Could not find a project named: " + ProjectName);

            Log.Debug("Finding deployment process for project: " + ProjectName);
            var deploymentProcess = Repository.DeploymentProcesses.Get(project.DeploymentProcessId);

            Log.Debug("Finding release template...");
            var releaseTemplate = Repository.DeploymentProcesses.GetTemplate(deploymentProcess);

            var plan = new ReleasePlan(releaseTemplate, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    if (!unresolved.IsResolveable)
                    {
                        Log.ErrorFormat("The version number for step '{0}' cannot be automatically resolved because the feed or package ID is dynamic.", unresolved.StepName);
                        continue;
                    }

                    Log.Debug("Finding latest NuGet package for step: " + unresolved.StepName);

                    var feed = Repository.Feeds.Get(unresolved.NuGetFeedId);
                    if (feed == null)
                        throw new CommandException(string.Format("Could not find a feed with ID {0}, which is used by step: " + unresolved.StepName, unresolved.NuGetFeedId));

                    var packages = Repository.Client.Get<List<PackageResource>>(feed.Link("VersionsTemplate"), new {packageIds = new[] {unresolved.PackageId}});
                    var version = packages.FirstOrDefault();
                    if (version == null)
                    {
                        Log.ErrorFormat("Could not find any packages with ID '{0}' in the feed '{1}'", unresolved.PackageId, feed.FeedUri);
                    }
                    else
                    {
                        unresolved.SetVersionFromLatest(version.Version);
                    }
                }
            }

            var versionNumber = VersionNumber;
            if (string.IsNullOrWhiteSpace(versionNumber))
            {
                Log.Warn("A --version parameter was not specified, so a version number was automatically selected based on the highest package version.");
                versionNumber = plan.GetHighestVersionNumber();
            }

            if (plan.Steps.Count > 0)
            {
                Log.Info("Release plan for release:    " + versionNumber);
                Log.Info("Steps: ");
                Log.Info(plan.FormatAsTable());
            }

            if (plan.HasUnresolvedSteps())
            {
                throw new CommandException("Package versions could not be resolved for one or more of the package steps in this release. See the errors above for details. Either ensure the latest version of the package can be automatically resolved, or set the version to use specifically by using the --package argument.");
            }

            Log.Debug("Creating release...");

            if (IgnoreIfAlreadyExists)
            {
                var found = Repository.Releases.FindOne(r => r.Version == versionNumber);
                if (found != null)
                {
                    Log.Info("A release with the number " + versionNumber + " already exists.");
                    return;
                }
            }

            var release = Repository.Releases.Create(new ReleaseResource(versionNumber, project.Id)
            {
                ReleaseNotes = ReleaseNotes,
                SelectedPackages = plan.GetSelections()
            });
            Log.Info("Release " + release.Version + " created successfully!");

            Log.ServiceMessage("setParameter", new { name = "octo.releaseNumber", value = release.Version });

            DeployRelease(project, release, DeployToEnvironmentNames);
        }
Beispiel #6
0
        protected override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName))
            {
                throw new CommandException("Please specify a project name using the parameter: --project=XYZ");
            }

            Log.Debug("Finding project: " + ProjectName);
            var project = Repository.Projects.FindByName(ProjectName);

            if (project == null)
            {
                throw new CommandException("Could not find a project named: " + ProjectName);
            }

            Log.Debug("Finding deployment process for project: " + ProjectName);
            var deploymentProcess = Repository.DeploymentProcesses.Get(project.DeploymentProcessId);

            Log.Debug("Finding release template...");
            var releaseTemplate = Repository.DeploymentProcesses.GetTemplate(deploymentProcess);

            var plan = new ReleasePlan(releaseTemplate, versionResolver);

            if (plan.UnresolvedSteps.Count > 0)
            {
                Log.Debug("Resolving NuGet package versions...");
                foreach (var unresolved in plan.UnresolvedSteps)
                {
                    if (!unresolved.IsResolveable)
                    {
                        Log.ErrorFormat("The version number for step '{0}' cannot be automatically resolved because the feed or package ID is dynamic.", unresolved.StepName);
                        continue;
                    }

                    Log.Debug("Finding latest NuGet package for step: " + unresolved.StepName);

                    var feed = Repository.Feeds.Get(unresolved.NuGetFeedId);
                    if (feed == null)
                    {
                        throw new CommandException(string.Format("Could not find a feed with ID {0}, which is used by step: " + unresolved.StepName, unresolved.NuGetFeedId));
                    }

                    var packages = Repository.Client.Get <List <PackageResource> >(feed.Link("VersionsTemplate"), new { packageIds = new[] { unresolved.PackageId } });
                    var version  = packages.FirstOrDefault();
                    if (version == null)
                    {
                        Log.ErrorFormat("Could not find any packages with ID '{0}' in the feed '{1}'", unresolved.PackageId, feed.FeedUri);
                    }
                    else
                    {
                        unresolved.SetVersionFromLatest(version.Version);
                    }
                }
            }

            var versionNumber = VersionNumber;

            if (string.IsNullOrWhiteSpace(versionNumber))
            {
                Log.Warn("A --version parameter was not specified, so a version number was automatically selected based on the highest package version.");
                versionNumber = plan.GetHighestVersionNumber();
            }

            if (plan.Steps.Count > 0)
            {
                Log.Info("Release plan for release:    " + versionNumber);
                Log.Info("Steps: ");
                Log.Info(plan.FormatAsTable());
            }

            if (plan.HasUnresolvedSteps())
            {
                throw new CommandException("Package versions could not be resolved for one or more of the package steps in this release. See the errors above for details. Either ensure the latest version of the package can be automatically resolved, or set the version to use specifically by using the --package argument.");
            }

            Log.Debug("Creating release...");

            if (IgnoreIfAlreadyExists)
            {
                var found = Repository.Releases.FindOne(r => r.Version == versionNumber);
                if (found != null)
                {
                    Log.Info("A release with the number " + versionNumber + " already exists.");
                    return;
                }
            }

            var release = Repository.Releases.Create(new ReleaseResource(versionNumber, project.Id)
            {
                ReleaseNotes     = ReleaseNotes,
                SelectedPackages = plan.GetSelections()
            });

            Log.Info("Release " + release.Version + " created successfully!");

            Log.ServiceMessage("setParameter", new { name = "octo.releaseNumber", value = release.Version });

            DeployRelease(project, release, DeployToEnvironmentNames);
        }