Ejemplo n.º 1
0
        public OctopusDeployReleaseCreatorFixture(FilePath toolPath = null, bool defaultToolExist = true)
        {
            Process = Substitute.For <IProcess>();
            Process.GetExitCode().Returns(0);

            ProcessRunner = Substitute.For <IProcessRunner>();
            ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process);

            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            Globber = Substitute.For <IGlobber>();
            Globber.Match("./tools/**/Octo.exe").Returns(new[] { (FilePath)"/Working/tools/Octo.exe" });

            FileSystem = Substitute.For <IFileSystem>();
            FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/Octo.exe")).Returns(defaultToolExist);

            if (toolPath != null)
            {
                FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true);
            }

            ProjectName = "testProject";
            Settings    = new CreateReleaseSettings
            {
                Server = "http://octopus",
                ApiKey = "API-12345"
            };
        }
Ejemplo n.º 2
0
        public void CreateOctopusRelease(string projectName, VersionResult version, string apiUrl, string apiKey)
        {
            if (string.IsNullOrEmpty(apiUrl))
            {
                _log.Error("apiUrl canot be empty");
                return;
            }
            if (string.IsNullOrEmpty(apiKey))
            {
                _log.Error("apiKey canot be empty");
                return;
            }
            if (string.IsNullOrEmpty(projectName))
            {
                _log.Error("Project name canot be empty");
                return;
            }
            _log.Information($"Creating octopus release {version.FullVersion}");
            var settings = new CreateReleaseSettings
            {
                EnableDebugLogging    = _log.Verbosity > Verbosity.Normal,
                EnableServiceMessages = false,               // Enables teamcity services messages when logging
                ReleaseNumber         = version.FullVersion,
                DefaultPackageVersion = version.FullVersion, // All packages in the release should be x.x.x.x
                // One or the other
                ReleaseNotes = CommitMessageShort,
                //ReleaseNotesFile = "./ReleaseNotes.md",
                Server = apiUrl,
                ApiKey = apiKey
                         //IgnoreExisting = true // if this release number already exists, ignore it
                         //ToolPath = "./tools/OctopusTools/Octo.exe"
                         //IgnoreSslErrors = true,
                         //Packages = new Dictionary<string, string>
                         //            {
                         //                { "PackageOne", "1.0.2.3" },
                         //                { "PackageTwo", "5.2.3" }
                         //            },
                         //PackagesFolder = @"C:\MyOtherNugetFeed",
            };
            var octoRelease = new OctopusDeployReleaseCreator(_fileSystem, _environment, _processRunner, _tools);

            octoRelease.CreateRelease(projectName, settings);

            if (IsAppVeyor)
            {
                _appVeyorProvider.AddInformationalMessage($"Octopus release {version.FullVersion} created.");
            }
        }
Ejemplo n.º 3
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));
        }