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.

example:

$Project = Get-OctopusProject -ProjectName 'ProjectName' -ResourceOnly -Verbose
$process = $con.Repository.DeploymentProcesses.get($Project.DeploymentProcessId)
  ## View Environments
$process.Steps[0].Actions.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,
Danny

Hi,

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

##Setup##
$ProjectName = "MyProject"
$EnvironmentName = "MyEnvironment"

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

$c = New-OctopusConnection

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

$process.Steps[0].Actions[0].Environments.Add($Environment.id)

$c.Repository.DeploymentProcesses.Modify($process)

Hope that helps,
Dalmiro

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.

Thanks,
Dalmiro