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); }
/// <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)); } }
public static async Task <DeploymentStep> ToModel(this DeploymentStepResource resource, IOctopusAsyncRepository repository) { return(new DeploymentStep( resource.Name, (DeploymentStep.StepCondition)resource.Condition, resource.RequiresPackagesToBeAcquired, (DeploymentStep.StepStartTrigger)resource.StartTrigger, resource.Properties.ToModel(), await Task.WhenAll(resource.Actions.Select(a => a.ToModel(repository))))); }
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", It.IsAny <string>(), It.IsAny <object>())).Returns(project); octoRepo.Setup(o => o.Projects.FindByName("Gibberish", It.IsAny <string>(), It.IsAny <object>())).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.Properties.Add("SomethingElse", new PropertyValueResource("Secret", true)); 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 static async Task <DeploymentStepResource> UpdateWith(this DeploymentStepResource resource, DeploymentStep model, IOctopusAsyncRepository repository) { resource.Name = model.Name; resource.Condition = (DeploymentStepCondition)model.Condition; resource.RequiresPackagesToBeAcquired = model.RequiresPackagesToBeAcquired; resource.StartTrigger = (DeploymentStepStartTrigger)model.StartTrigger; resource.Properties.UpdateWith(model.Properties); resource.Actions.Clear(); foreach (var action in model.Actions.Select(a => new DeploymentActionResource().UpdateWith(a, repository))) { resource.Actions.Add(await action); } return(resource); }
/// <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); }
private void CopyActions(DeploymentStepResource step, DeploymentStepResource newStep) { foreach (var action in step.Actions) { var newAction = new DeploymentActionResource { Name = GetName(action.Name), ActionType = action.ActionType, }; newAction.Environments.AddRange(action.Environments); newAction.Properties.AddRange(action.Properties); newAction.SensitiveProperties.AddRange(action.SensitiveProperties); newStep.Actions.Add(newAction); } }
/// <summary> /// ProcessRecord /// </summary> protected override void ProcessRecord() { var clone = new DeploymentStepResource { Name = GetName(_step.Name), Condition = _step.Condition, RequiresPackagesToBeAcquired = _step.RequiresPackagesToBeAcquired, }; foreach (var property in _step.Properties) { clone.Properties.Add(property.Key, property.Value); } CopyActions(_step, clone); _deploymentProcess.Steps.Add(clone); }
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); } }
private static DeploymentStepResource GetSimpleScriptStep(int id) { var step = new DeploymentStepResource() { Name = "Script " + id }; step.Actions.Add(new DeploymentActionResource() { Name = "Script" + id, ActionType = "Octopus.Script" }); step.Actions[0].Properties.Clear(); step.Actions[0].Properties["Octopus.Action.Script.ScriptSource"] = "Inline"; step.Actions[0].Properties["Octopus.Action.Script.ScriptBody"] = "'Hello World'"; step.Properties["Octopus.Action.TargetRoles"] = "InstallStuff"; return(step); }
/// <summary> /// A simple script step that prints "Hello World" using Powershell. /// </summary> /// <returns>DeploymentStepResource</returns> public static DeploymentStepResource GetSimpleScriptStep() { var step = new DeploymentStepResource() { Name = "Script Step" }; step.Actions.Add(new DeploymentActionResource() { Name = "Script Step", ActionType = "Octopus.Script" }); step.Actions[0].Properties.Clear(); step.Actions[0].Properties["Octopus.Action.Script.ScriptSource"] = "Inline"; step.Actions[0].Properties["Octopus.Action.RunOnServer"] = "true"; step.Actions[0].Properties["Octopus.Action.Script.ScriptBody"] = "'Hello World'"; step.Properties["Octopus.Action.TargetRoles"] = "default-role"; return(step); }
private void CopyProcess() { foreach (var step in _oldProcess.Steps) { var newStep = new DeploymentStepResource { Name = step.Name, Condition = step.Condition, RequiresPackagesToBeAcquired = step.RequiresPackagesToBeAcquired, }; foreach (var property in step.Properties) { newStep.Properties.Add(property.Key, property.Value); } CopyActions(step, newStep); _newProcess.Steps.Add(newStep); } }
private void CopyActions(DeploymentStepResource step, DeploymentStepResource newStep) { foreach (var action in step.Actions) { var newAction = new DeploymentActionResource { Name = GetName(action.Name), ActionType = action.ActionType, }; foreach (var env in action.Environments) { newAction.Environments.Add(env); } foreach (var property in action.Properties) { newAction.Properties.Add(property.Key, property.Value); } newStep.Actions.Add(newAction); } }
private static DeploymentStepResource GetPackageDeploymentStep(int id) { var step = new DeploymentStepResource() { Name = "Web " + id }; step.Actions.Add(new DeploymentActionResource() { Name = "Web" + id, ActionType = "Octopus.TentaclePackage" }); step.Actions[0].Properties.Clear(); step.Actions[0].Properties["Octopus.Action.EnabledFeatures"] = "Octopus.Features.ConfigurationTransforms,Octopus.Features.ConfigurationVariables"; step.Actions[0].Properties["Octopus.Action.Package.AutomaticallyRunConfigurationTransformationFiles"] = "True"; step.Actions[0].Properties["Octopus.Action.Package.AutomaticallyUpdateAppSettingsAndConnectionStrings"] = "True"; step.Actions[0].Properties["Octopus.Action.Package.DownloadOnTentacle"] = "False"; step.Actions[0].Properties["Octopus.Action.Package.NuGetFeedId"] = "feeds-builtin"; step.Actions[0].Properties["Octopus.Action.Package.NuGetPackageId"] = "Acme.Web"; step.Properties["Octopus.Action.TargetRoles"] = "InstallStuff"; return(step); }
private static DeploymentStepResource GetLargeStep(int id) { var step = new DeploymentStepResource() { Name = "Script " + id }; step.Actions.Add(new DeploymentActionResource() { Name = "Script" + id, ActionType = "Octopus.Script" }); step.Actions[0].Properties.Clear(); step.Actions[0].Properties["Octopus.Action.Script.ScriptSource"] = "Inline"; step.Actions[0].Properties["Octopus.Action.Script.ScriptBody"] = "$OctopusParameters.GetEnumerator() | % { $_.Key + '=' + $_.Value }"; for (int x = 1; x < 20; x++) { step.Actions[0].Properties[$"FillerProperty{x:000}"] = AReallyBigString; } step.Properties["Octopus.Action.TargetRoles"] = "InstallStuff"; return(step); }
static void Main(string[] args) { var octoUrl = ""; var apiKey = ""; var client = new OctopusClient(new OctopusServerEndpoint(octoUrl, apiKey)); var repo = new OctopusRepository(client); //Project you want to create or modify var project = new ProjectResource { Name = "", //name of project ProjectGroupId = "", //group project should be added to. to find by name: repo.ProjectGroups.FindByName("").Id) LifecycleId = "" //lifecycle project should use. to find by name: repo.Lifecycles.FindByName("").Id }; var newproject = repo.Projects.FindByName(project.Name); //Check if project exists, if not create it if (newproject == null) { //Creates Project repo.Projects.Create(project); //get the new project newproject = repo.Projects.FindByName(project.Name); } if (newproject == null) { Console.WriteLine($"{project.Name} didn't exist, creating..."); repo.Projects.Create(project); Console.WriteLine($"New Project {project.Name} Created!"); newproject = repo.Projects.FindByName(project.Name); } Console.WriteLine($"New Project {project.Name} Found"); //This will find the step template you want to add var chainStepTemplate = repo.ActionTemplates.FindByName("Step Template"); //Change this to the name of your step template to add Console.WriteLine("Template Found"); //Get the deployment process for the project var deploymentProcess = repo.DeploymentProcesses.Get(newproject.DeploymentProcessId); //Initialize a new Deployment Step Resource var deploymentStep = new DeploymentStepResource { Name = "New Step", //Change this to what you want the step to be named. Condition = DeploymentStepCondition.Success, StartTrigger = DeploymentStepStartTrigger.StartAfterPrevious }; //Initialize new Action var action = new DeploymentActionResource { Name = deploymentStep.Name, ActionType = chainStepTemplate.ActionType, }; Console.WriteLine("Adding actions"); //Add the template Id action.Properties.Add(new KeyValuePair <string, PropertyValueResource>("Octopus.Action.Template.Id", chainStepTemplate.Id)); //Add the template Version action.Properties.Add(new KeyValuePair <string, PropertyValueResource>("Octopus.Action.Template.Version", chainStepTemplate.Version.ToString())); //Add the parameters for the step template and any default values. Modify this to set other values. foreach (var parameter in chainStepTemplate.Parameters) { var property = new KeyValuePair <string, PropertyValueResource>(parameter.Name, parameter.DefaultValue); action.Properties.Add(property); Console.WriteLine($"{parameter.Name}"); } //Add the standard properties foreach (var property in chainStepTemplate.Properties) { action.Properties.Add(property); Console.WriteLine($"{property.Key}"); } //Add the action to your deployment step deploymentStep.Actions.Add(action); Console.WriteLine("Action added"); //Add your step to the deployment process deploymentProcess.Steps.Add(deploymentStep); Console.WriteLine("Step added to Deployment Process"); //Finally save the deployment process. try { repo.DeploymentProcesses.Modify(deploymentProcess); Console.WriteLine("Deployment Process was modified"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
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); }