Update a step's targeted environments via API

Hi. So using using the client.dll or via access the repository through Octoposh, I’m able to see which Environments a step has. However I’m unable to modify them. The property just seems to have a get accessor.


$Project = Get-OctopusProject -ProjectName 'ProjectName' -ResourceOnly -Verbose
$process = $con.Repository.DeploymentProcesses.get($Project.DeploymentProcessId)
  ## View Environments

But I’m unable to set the values for the environment to any other Environment Id’s. Is there a way I can do this from here?



Thanks for reaching out! This is how you’d do it with Octoposh:

$ProjectName = "MyProject"
$EnvironmentName = "MyEnvironment"

$Project = Get-OctopusProject -name $ProjectName -ResourceOnly -Verbose
$Environment = Get-OctopusEnvironment -name $EnvironmentName -ResourceOnly

$c = New-OctopusConnection

$process = $c.Repository.DeploymentProcesses.get($Project.DeploymentProcessId)



Hope that helps,

Thanks, that’s almost what I was doing. It wasn’t working as I hadn’t noticed that you could have multiple Actions against a step. When I now try with “Actions[0]” it works! Thanks Dalmiro.

Question though… In what situation would a step have more than one set of actions?

Hi Daniel,

Glad to hear its working now.

To answer your last question, that’ll happen when you have a rolling step with many child steps. In that case each child will be a different action.