public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddLibraryVariable));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            _variableSet.Variables.Clear();

            var lib = new LibraryVariableSetResource { Name = "Octopus" };
            var libs = new List<LibraryVariableSetResource> {lib};
            lib.Links.Add("Variables", "variablesets-1");
            octoRepo.Setup(o => o.LibraryVariableSets.FindOne(It.IsAny<Func<LibraryVariableSetResource, bool>>()))
                .Returns(
                    (Func<LibraryVariableSetResource, bool> f) =>
                        (from l in libs where f(l) select l).FirstOrDefault());

            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource)null);

            octoRepo.Setup(o => o.VariableSets.Get("variablesets-1")).Returns(_variableSet);

            var process = new DeploymentProcessResource();
            process.Steps.Add(new DeploymentStepResource { Name = "Website", Id = "Step-1" });
            octoRepo.Setup(o => o.DeploymentProcesses.Get("deploymentprocesses-1")).Returns(process);

            var envs = new List<EnvironmentResource>
            {
                new EnvironmentResource {Id = "Environments-1", Name = "DEV"}
            };

            octoRepo.Setup(o => o.Environments.FindByNames(new[] { "DEV" })).Returns(envs);
            var machines = new List<MachineResource>
            {
                new MachineResource {Id = "Machines-1", Name = "web-01"}
            };
            octoRepo.Setup(o => o.Machines.FindByNames(new[] { "web-01" })).Returns(machines);
        }
Пример #2
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddVariable));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            _variableSet.Variables.Clear();

            var project = new ProjectResource {DeploymentProcessId = "deploymentprocesses-1"};
            project.Links.Add("Variables", "variablesets-1");
            octoRepo.Setup(o => o.Projects.FindByName("Octopus")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource) null);

            octoRepo.Setup(o => o.VariableSets.Get("variablesets-1")).Returns(_variableSet);

            var process = new DeploymentProcessResource();
            process.Steps.Add(new DeploymentStepResource {Name = "Website", Id = "Step-1"});
            octoRepo.Setup(o => o.DeploymentProcesses.Get("deploymentprocesses-1")).Returns(process);

            var envs = new List<EnvironmentResource>
            {
                new EnvironmentResource {Id = "Environments-1", Name = "DEV"}
            };

            octoRepo.Setup(o => o.Environments.FindByNames(new[] {"DEV"})).Returns(envs);
            var machines = new List<MachineResource>
            {
                new MachineResource {Id = "Machines-1", Name = "web-01"}
            };
            octoRepo.Setup(o => o.Machines.FindByNames(new[] { "web-01" })).Returns(machines);
        }
Пример #3
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof (GetStep));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            const string deploymentProcessId = "deploymentprocess-projects-1";

            // Create a project
            var projectResources = new List<ProjectResource>
            {
                new ProjectResource {Name = "Octopus", DeploymentProcessId = deploymentProcessId, Id = "projects-1"}
            };

            octoRepo.Setup(o => o.Projects.FindByNames(new[] {"Octopus"})).Returns(projectResources);
            octoRepo.Setup(o => o.Projects.FindByNames(new[] {"Gibberish"})).Returns(new List<ProjectResource>());
            octoRepo.Setup(o => o.Projects.Get("projects-1")).Returns(projectResources[0]);
            octoRepo.Setup(o => o.Projects.Get("Gibberish")).Throws(new OctopusResourceNotFoundException("Not Found"));

            var process = new DeploymentProcessResource();
            //{
            //    Id = "deploymentprocess-projects-1"
            //};
            process.Steps.Add(new DeploymentStepResource { Name = "Test Step" });
            process.Steps.Add(new DeploymentStepResource { Name = "Test Step 2" });

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] {deploymentProcessId})))
                .Returns(process);

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsNotIn(new[] {deploymentProcessId})))
                .Throws(new OctopusResourceNotFoundException("Not Found"));
        }
Пример #4
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(UpdateVariable));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            var variable = new VariableResource
            {
                Id = "variables-1",
                Name = "Test",
                Value = "Test Value",
                IsSensitive = false
            };
            variable.Scope.Add(ScopeField.Action, "actions-1");
            variable.Scope.Add(ScopeField.Environment, "environments-1");
            variable.Scope.Add(ScopeField.Role, "DB");

            _variableSet.Variables.Add(variable);

            var project = new ProjectResource { DeploymentProcessId = "deploymentprocesses-1" };
            project.Links.Add("Variables", "variablesets-1");
            octoRepo.Setup(o => o.Projects.FindByName("Octopus")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource)null);

            octoRepo.Setup(o => o.VariableSets.Get("variablesets-1")).Returns(_variableSet);

            var process = new DeploymentProcessResource();
            process.Steps.Add(new DeploymentStepResource { Name = "Website", Id = "Step-1" });
            octoRepo.Setup(o => o.DeploymentProcesses.Get("deploymentprocesses-1")).Returns(process);

            var envs = new List<EnvironmentResource>
            {
                new EnvironmentResource {Id = "environments-1", Name = "DEV"},
                new EnvironmentResource {Id = "environments-2", Name = "TEST"}
            };

            octoRepo.Setup(o => o.Environments.FindByNames(It.IsAny<string[]>()))
                .Returns((string[] names) => (from n in names
                    from e in envs
                    where e.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase)
                    select e).ToList());

            var machines = new List<MachineResource>
            {
                new MachineResource {Id = "machines-1", Name = "db-01"},
                new MachineResource {Id = "machines-2", Name = "web-01"}
            };
            octoRepo.Setup(o => o.Machines.FindByNames(It.IsAny<string[]>())).Returns(
                (string[] names) => (from n in names
                                     from m in machines
                                     where m.Name.Equals(n, StringComparison.InvariantCultureIgnoreCase)
                                     select m).ToList());
        }
Пример #5
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(CopyStep));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create project
            var project = new ProjectResource
            {
                Name = "Octopus",
                Description = "Test Source",
                DeploymentProcessId = "deploymentprocesses-1",
                VariableSetId = "variablesets-1",
            };

            // Create projects
            octoRepo.Setup(o => o.Projects.FindByName("Octopus")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource)null);

            // Create deployment process
            var action = new DeploymentActionResource { Name = "NuGet", ActionType = "NuGet" };
            action.Environments.Add("environments-1");
            action.Properties.Add("Something", "Value");
            action.SensitiveProperties.Add("SomethingElse", "Secret");

            var step = new DeploymentStepResource { Id = "deploymentsteps-1", Name = "Website" };
            step.Actions.Add(action);

            _process = new DeploymentProcessResource();
            _process.Steps.Add(step);

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-1" }))).Returns(_process);
            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-2" }))).Returns(new DeploymentProcessResource());

            // Create variable set
            var variable = new VariableResource { Name = "Name", Value = "Value" };
            variable.Scope.Add(ScopeField.Action, "DeploymentsActions-1");
            variable.Scope.Add(ScopeField.Environment, "Environments-1");

            var variableSet = new VariableSetResource();
            variableSet.Variables.Add(variable);

            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-1" }))).Returns(variableSet);
            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(new VariableSetResource());
        }
Пример #6
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetAction));

            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create a project
            var projectResource = new ProjectResource {Name = "Octopus"};
            octoRepo.Setup(o => o.Projects.FindByName("Octopus")).Returns(projectResource);

            // Create a deployment process
            var stepResource = new DeploymentStepResource();
            stepResource.Actions.Add(new DeploymentActionResource { Name = "Do Stuff", Id = "Globally unique identifier"});
            stepResource.Actions.Add(new DeploymentActionResource { Name = "Do Other Stuff", Id = "Universally unique identifier" });

            var dpResource = new DeploymentProcessResource();
            dpResource.Steps.Add(stepResource);

            var dpRepo = new Mock<IDeploymentProcessRepository>();
            dpRepo.Setup(d => d.Get(It.IsAny<string>())).Returns(dpResource);

            octoRepo.Setup(o => o.DeploymentProcesses).Returns(dpRepo.Object);
        }
 public static void UpdateProcessVersion(string projectSlug, OctopusRepository octopusRepository,
     ProjectResource project, DeploymentProcessResource deploymentProcessResource)
 {
     var process = octopusRepository.DeploymentProcesses.Get(project.DeploymentProcessId);
     deploymentProcessResource.Version = process.Version;
 }
Пример #8
0
        /// <summary>
        /// ProcessRecord
        /// </summary>
        protected override void ProcessRecord()
        {
            _oldProject = _octopus.Projects.FindByName(Name);

            if (_oldProject == null)
                throw new Exception(string.Format("Project '{0}' was not found.", Name));

            var group = _octopus.ProjectGroups.FindByName(ProjectGroup);

            if (group == null)
                throw new Exception(string.Format("Project Group '{0}' was not found.", ProjectGroup));

            CreateNewProject(group.Id);

            _oldProcess = _octopus.DeploymentProcesses.Get(_oldProject.DeploymentProcessId);
            _newProcess = _octopus.DeploymentProcesses.Get(_newProject.DeploymentProcessId);

            CopyProcess();
            CopyVariables();
        }
Пример #9
0
 /// <summary>
 /// EndProcessing
 /// </summary>
 protected override void EndProcessing()
 {
     WriteVerbose("Saving the deployment process...");
     _newProcess = _octopus.DeploymentProcesses.Modify(_newProcess);
     WriteVerbose("Deployment process saved.");
 }
 private static bool HasAnyRole(DeploymentProcessResource deploymentProcess, IEnumerable<string> roles)
 {
     foreach (var step in deploymentProcess.Steps) 
     {
         PropertyValueResource targetRolesProperty;
         if (step.Properties.TryGetValue("Octopus.Action.TargetRoles", out targetRolesProperty))
         {
             var targetRoles = targetRolesProperty.Value.Split(',');
             if (roles.Intersect(targetRoles).Any())
             {
                 return true;
             }
         }
     }
     
     return false;
 }
        public ChannelResource AddCommonRuleForAllActions(string versionRange, string tagRegex, DeploymentProcessResource process)
        {
            var actionsWithPackage = process.Steps.SelectMany(s => s.Actions.Where(a => a.Properties.Any(p => p.Key == "Octopus.Action.Package.PackageId"))).ToArray();

            return(AddRule(versionRange, tagRegex, actionsWithPackage));
        }
Пример #12
0
        void ImportDeploymentProcess(DeploymentProcessResource deploymentProcess,
            ProjectResource importedProject,
            IDictionary<string, EnvironmentResource> environments,
            IDictionary<string, FeedResource> nugetFeeds,
            IDictionary<string, ActionTemplateResource> actionTemplates)
        {
            Log.Debug("Importing the Projects Deployment Process");
            var existingDeploymentProcess = Repository.DeploymentProcesses.Get(importedProject.DeploymentProcessId);
            var steps = deploymentProcess.Steps;
            foreach (var step in steps)
            {
                foreach (var action in step.Actions)
                {
                    if (action.Properties.ContainsKey("Octopus.Action.Package.NuGetFeedId"))
                    {
                        Log.Debug("Updating ID of NuGet Feed");
                        var nugetFeedId = action.Properties["Octopus.Action.Package.NuGetFeedId"];
                        action.Properties["Octopus.Action.Package.NuGetFeedId"] = nugetFeeds[nugetFeedId].Id;
                    }
                    if (action.Properties.ContainsKey("Octopus.Action.Template.Id"))
                    {
                        Log.Debug("Updating ID and version of Action Template");
                        var templateId = action.Properties["Octopus.Action.Template.Id"];
                        var template = actionTemplates[templateId];
                        action.Properties["Octopus.Action.Template.Id"] = template.Id;
                        action.Properties["Octopus.Action.Template.Version"] = template.Version.ToString(CultureInfo.InvariantCulture);
                    }
                    var oldEnvironmentIds = action.Environments;
                    var newEnvironmentIds = new List<string>();
                    Log.Debug("Updating IDs of Environments");
                    foreach (var oldEnvironmentId in oldEnvironmentIds)
                    {
                        newEnvironmentIds.Add(environments[oldEnvironmentId].Id);
                    }
                    action.Environments.Clear();
                    action.Environments.AddRange(newEnvironmentIds);
                }
            }
            existingDeploymentProcess.Steps.Clear();
            existingDeploymentProcess.Steps.AddRange(steps);

            Repository.DeploymentProcesses.Modify(existingDeploymentProcess);
        }
Пример #13
0
 public ChannelResource AddCommonRuleForAllActions(string versionRange, string tagRegex, DeploymentProcessResource process)
 {
     var actionsWithPackage = process.Steps.SelectMany(s => s.Actions.Where(a => a.Properties.Any(p => p.Key == "Octopus.Action.Package.PackageId"))).ToArray();
     return AddRule(versionRange, tagRegex, actionsWithPackage);
 }
 public static void ImportProcess(OctopusRepository octopusRepository, ProjectResource createdProject,
     DeploymentProcessResource process)
 {
     process.ProjectId = createdProject.Id;
     process.Id = string.Format("deploymentprocess-{0}", createdProject.Id);
     process.Links["Self"] = string.Format("/api/deploymentprocesses/{0}", createdProject.DeploymentProcessId);
     process.Version = 0;
     octopusRepository.DeploymentProcesses.Modify(process);
 }
Пример #15
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof (CopyProject));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create a project group
            var groupResource = new ProjectGroupResource {Name = "Octopus", Id = "projectgroups-1"};
            octoRepo.Setup(o => o.ProjectGroups.FindByName("Octopus")).Returns(groupResource);
            octoRepo.Setup(o => o.ProjectGroups.FindByName("Gibberish")).Returns((ProjectGroupResource) null);

            // Create project
            var project = new ProjectResource
            {
                Name = "Source",
                Description = "Test Source",
                DeploymentProcessId = "deploymentprocesses-1",
                VariableSetId = "variablesets-1",
                DefaultToSkipIfAlreadyInstalled = true,
                IncludedLibraryVariableSetIds = new List<string> { "libraryvariablesets-1" },
                VersioningStrategy = new VersioningStrategyResource(),
                AutoCreateRelease = false,
                ReleaseCreationStrategy = new ReleaseCreationStrategyResource(),
                IsDisabled = false,
                LifecycleId = "lifecycle-1"
            };

            // Create projects
            _projects.Clear();
            _projects.Add(project);

            octoRepo.Setup(o => o.Projects.FindByName("Source")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource) null);
            octoRepo.Setup(o => o.Projects.Create(It.IsAny<ProjectResource>())).Returns(
                delegate(ProjectResource p)
                {
                    p.VariableSetId = "variablesets-2";
                    p.DeploymentProcessId = "deploymentprocesses-2";
                    _projects.Add(p);
                    return p;
                }
            );

            // Create deployment process
            var action = new DeploymentActionResource {Name = "Action"};
            action.Environments.Add("environments-1");

            var step = new DeploymentStepResource { Id = "deploymentsteps-1", Name = "Database"};
            step.Actions.Add(action);

            var process = new DeploymentProcessResource();
            process.Steps.Add(step);

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-1" }))).Returns(process);
            _copyProcess = new DeploymentProcessResource();
            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-2" }))).Returns(_copyProcess);

            // Create variable set
            var variable = new VariableResource { Name = "Name", Value = "Value" };
            variable.Scope.Add(ScopeField.Action, "deploymentsactions-1");
            variable.Scope.Add(ScopeField.Environment, "environments-1");

            var sourceVariables = new VariableSetResource();
            sourceVariables.Variables.Add(variable);

            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-1" }))).Returns(sourceVariables);
            _copyVariables = new VariableSetResource();
            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(_copyVariables);
        }
Пример #16
0
        /// <summary>
        /// BeginProcessing
        /// </summary>
        protected override void BeginProcessing()
        {
            _octopus = Session.RetrieveSession(this);

            // Find the project that owns the variables we want to get
            var project = _octopus.Projects.FindByName(Project);

            if (project == null)
            {
                const string msg = "Project '{0}' was not found.";
                throw new Exception(string.Format(msg, Project));
            }

            var id = project.DeploymentProcessId;
            _deploymentProcess = _octopus.DeploymentProcesses.Get(id);
        }
Пример #17
0
        /// <summary>
        /// BeginProcessing
        /// </summary>
        protected override void BeginProcessing()
        {
            _octopus = Session.RetrieveSession(this);

            // Find the project that owns the variables we want to get
            var project = _octopus.Projects.FindByName(Project);

            if (project == null)
            {
                const string msg = "Project '{0}' was not found.";
                throw new Exception(string.Format(msg, Project));
            }

            var id = project.DeploymentProcessId;
            _deploymentProcess = _octopus.DeploymentProcesses.Get(id);

            var steps = from s in _deploymentProcess.Steps
                        where s.Name.Equals(Name, StringComparison.InvariantCultureIgnoreCase)
                        select s;

            _step = steps.FirstOrDefault();

            if (_step == null)
                throw new Exception(string.Format("Step with name '{0}' was not found.", Name));
        }