示例#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 = 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 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);
        }
示例#4
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);
        }