private static string GetNuGetPackageIdFromAction(DeploymentActionResource action) { PropertyValueResource nuGetPackageId; if (action.Properties.TryGetValue("Octopus.Action.Package.NuGetPackageId", out nuGetPackageId)) { // some packages are actually referenced by hashes (so a.Properties["Octopus.Action.Package.NuGetPackageId"] = "{#NuGetPackage}") var regexPattern = @"\#\{[a-zA-Z]+\}"; var regex = new Regex(regexPattern, RegexOptions.IgnoreCase); var match = regex.Match(nuGetPackageId.Value); if (match.Success) { // TODO: clean up this refKey nonsense var refKey = nuGetPackageId.Value.Replace("#{", "").Replace("}", ""); nuGetPackageId = action.Properties[refKey]; } } return nuGetPackageId.Value; }
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()); }
public DeploymentActionResource AddOrUpdateAction(string name) { var existing = FindAction(name); DeploymentActionResource action; if (existing == null) { action = new DeploymentActionResource { Name = name }; Actions.Add(action); } else { existing.Name = name; action = existing; } // Return the action so you can make customizations return action; }
public DeploymentActionResource AddOrUpdateAction(string name) { var existing = FindAction(name); DeploymentActionResource action; if (existing == null) { action = new DeploymentActionResource { Name = name }; Actions.Add(action); } else { existing.Name = name; action = existing; } // Return the action so you can make customizations return(action); }
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 ActionsAreEquals(this DeploymentActionResource dpar1, DeploymentActionResource dpar2) { return dpar1.ActionType == dpar2.ActionType && dpar1.Name == dpar2.Name; }
public void With_Arguments() { // Execute cmdlet _ps.AddCommand(CmdletName) .AddArgument("Octopus") .AddArgument("Website") .AddArgument("Webservice"); _ps.Invoke(); Assert.AreEqual(2, _process.Steps.Count); var step = _process.Steps[1]; Assert.AreEqual("Webservice", step.Name); Assert.AreNotEqual("deploymentsteps-1", step.Id); var action = new DeploymentActionResource { Name = "Webservice" }; action.Environments.Add("environments-1"); var actionResource = step.Actions[0]; Assert.AreEqual(action.Name, actionResource.Name); Assert.AreEqual("NuGet", actionResource.ActionType); Assert.AreEqual(action.Environments.ToString(), actionResource.Environments.ToString()); Assert.IsTrue(actionResource.Properties.ContainsKey("Something")); Assert.AreEqual("Value", actionResource.Properties["Something"]); Assert.AreEqual("Secret", actionResource.SensitiveProperties["SomethingElse"]); }
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); }
private static string GetNuGetFeedIdFromAction(DeploymentActionResource action) { PropertyValueResource nuGetFeed; return action.Properties.TryGetValue("Octopus.Action.Package.NuGetFeedId", out nuGetFeed) ? nuGetFeed.Value : null; }