public DeploymentStepResource AddOrUpdateStep(string name)
        {
            var existing = FindStep(name);

            DeploymentStepResource step;

            if (existing == null)
            {
                step = new DeploymentStepResource
                {
                    Name = name
                };

                Steps.Add(step);
            }
            else
            {
                existing.Name = name;

                step = existing;
            }

            // Return the step so you can add actions
            return(step);
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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 DeploymentStepResource AddOrUpdateStep(string name)
        {
            var existing = FindStep(name);

            DeploymentStepResource step;
            if (existing == null)
            {
                step = new DeploymentStepResource
                {
                    Name = name
                };

                Steps.Add(step);
            }
            else
            {
                existing.Name = name;

                step = existing;
            }

            // Return the step so you can add actions
            return step;
        }
Ejemplo n.º 5
0
        private void CopyProcess()
        {
            foreach (var step in _oldProcess.Steps)
            {
                var newStep = new DeploymentStepResource
                {
                    Name = step.Name,
                    Condition = step.Condition,
                    RequiresPackagesToBeAcquired = step.RequiresPackagesToBeAcquired,
                };

                newStep.Properties.AddRange(step.Properties);
                newStep.SensitiveProperties.AddRange(step.SensitiveProperties);

                CopyActions(step, newStep);

                _newProcess.Steps.Add(newStep);
            }
        }
Ejemplo n.º 6
0
        private static void CopyActions(DeploymentStepResource step, DeploymentStepResource newStep)
        {
            foreach (var action in step.Actions)
            {
                var newAction = new DeploymentActionResource
                {
                    Name = action.Name,
                    ActionType = action.ActionType,
                };

                newAction.Environments.AddRange(action.Environments);
                newAction.Properties.AddRange(action.Properties);
                newAction.SensitiveProperties.AddRange(action.SensitiveProperties);

                newStep.Actions.Add(newAction);
            }
        }
        public static bool ProcessesAreEquals(this DeploymentStepResource dpsr1, DeploymentStepResource dpsr2)
        {
            var cond1 = dpsr1.Name == dpsr2.Name;
            var listActionsBool = new List<bool>();

            for (var i = 0; i < dpsr1.Actions.Count; i++)
            {
                if (dpsr1.Actions[i].Name.Equals(dpsr2.Actions[i].Name) &&
                    dpsr1.Actions[i].ActionType.Equals(dpsr2.Actions[i].ActionType))
                {
                    listActionsBool.Add(true);
                }

                else
                {
                    listActionsBool.Add(false);
                }
            }
            var cond2 = !listActionsBool.Contains(false);
            var cond3 = dpsr1.Condition == dpsr2.Condition;
            return cond1 && cond2 && cond3;
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// ProcessRecord
        /// </summary>
        protected override void ProcessRecord()
        {
            var clone = new DeploymentStepResource
            {
                Name = GetName(_step.Name),
                Condition = _step.Condition,
                RequiresPackagesToBeAcquired = _step.RequiresPackagesToBeAcquired,
            };

            clone.Properties.AddRange(_step.Properties);
            clone.SensitiveProperties.AddRange(_step.SensitiveProperties);

            CopyActions(_step, clone);

            _deploymentProcess.Steps.Add(clone);
        }