I’m working on a case in which:
- have to add a “script step” to all projects that already have a step “Deploy to IIS”. Script step should be after “Deploy to IIS”
This part I’m not sure how to perform…
- “Script step” should be added to “Webserver” role and only to be applied in “Stage” environments
Wrote something but can’t find a way to create a step for the particular environment. I tied with Properties.Add, also tied with Id and Name…
Octopus vesrion: 2018.7.11
Add-Type -Path 'Octopus.Client.dll' $apikey = 'API-******' $octopusURI = 'http://*****.com' $projectId = "Projects-321" # Get this from /api/projects $stepName = "Run Website Inspection" # The name of the step $role = "Webserver" # The machine role to run this step on $environment = "STAGE" $scriptBody = "Write-Host 'Script body'" # The script to run $endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey $repository = New-Object Octopus.Client.OctopusRepository $endpoint $project = $repository.Projects.Get($projectId) $process = $repository.DeploymentProcesses.Get($project.DeploymentProcessId) $environmentToAdd = $repository.Environments.FindByName($environment) $step = New-Object Octopus.Client.Model.DeploymentStepResource $step.Name = $stepName $step.Condition = [Octopus.Client.Model.DeploymentStepCondition]::Success $step.Properties.Add("Octopus.Action.TargetRoles", $role) $step.Environment.Name = $environment1 $step.Octopus.Environment.Id($environmentToAdd.Id) # -> here I have trouble to understand how to stick environment $scriptAction = New-Object Octopus.Client.Model.DeploymentActionResource $scriptAction.ActionType = "Octopus.Script" $scriptAction.Name = $stepName $scriptAction.Properties.Add("Octopus.Action.Script.ScriptBody", $scriptBody) $step.Actions.Add($scriptAction) $process.Steps.Add($step) $repository.DeploymentProcesses.Modify($process)
Any help is welcome… Thank you in advance.