Powershell Client - Saving a deployment process

One of our deployment templates is associated with a large number of project steps (650+). When the project steps were created, the default value for the parameter variable was used; however, I’m looking for a way to programatically change the value in the project steps.

After a little bit of digging I found the step’s action property (deployment process). After updating the property I can’t figure out how to save it. If I use the ‘modify’ method for the deployment process I get a 'Cannot find an overload for “Modify” and the argument count: “1” ’ error because the method is looking for type ‘DeploymentProcessResource’ but the deployment process object is type ‘DeploymentStepResource’.

Here’s a generic version of my code which hopefully shows what I’m trying to do:

$srvURI = ‘http:///’
$srvApiKey = ‘’

$ep = New-Object Octopus.Client.OctopusServerEndpoint $srvURI,$srvApiKey
$repo = New-Object Octopus.Client.OctopusRepository $ep

$prjObj = $repository.Projects.FindByName(‘myProject’) # get project obj
$depProc = $repository.DeploymentProcesses.Get($prjObj.DeploymentProcessId) # get project deployment process
$depProc.actions.properties[’’] = ‘’ # update deployment process action property to new value
$repo.DeploymentProcesses.Modify($depProc) # save deployment process

Any thoughts on what I’m missing?

Thanks

S

Hi @snaulls,

Thanks for getting in touch! It looks like the problem you are encountering here is that you’re trying to perform a modify for the individual step resource. You will need to make your changes to the step, then perform the modify for the entire Deployment Process in order for Octopus to accept the modify.

This is probably the most common issue encountered when working with the Octopus.Client.

Let me know if this helps, or if you have any further questions at all here or are still stuck with this.

Best regards,
Daniel

Hi Daniel -

Thanks for the quick response. I"m resposting the code because some of the values were interpreted as markup so it looks a little strange:

$srvURI = 'http://octopuswebserver'
$srvApiKey = 'APIKey'

$ep = New-Object Octopus.Client.OctopusServerEndpoint $srvURI,$srvApiKey
$repo = New-Object Octopus.Client.OctopusRepository $ep

$prjObj = $repository.Projects.FindByName(‘myProject’) # get project obj
$depProc = $repository.DeploymentProcesses.Get($prjObj.DeploymentProcessId) 
$depProc.actions.properties['varname'] = 'new value' 
$repo.DeploymentProcesses.Modify($depProc)

In this example, I would think this line modifies the deployment process.
$repo.DeploymentProcesses.Modify($depProc) 

If I’m missing something, it would be helpful if you could post a simple example of how it can be done.

Thanks

S

Hi Daniel -

Any updates?

Hi @snaulls,

In the attached script I can see a potential issue. You are setting $repo for the OctopusRepository object, but later calling $depProc = $repository. This may just be specific to the example you have provided, but this would cause the script to not work. So assuming you are using $repo throughout the script, something like the following should work just fine.

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repo = New-Object Octopus.Client.OctopusRepository $endpoint

$prjObj = $repo.Projects.FindByName(‘CertTest’)
$depProc = $repo.DeploymentProcesses.Get($prjObj.DeploymentProcessId)
$depProc.Steps[3].RequiresPackagesToBeAcquired = 1
$repo.DeploymentProcesses.Modify($depProc)

This is a simple process to modify step 3 in my CertTest project to update a value to true. Saving the entire deployment process ($depProc) with the modify action. This works fine on my end.

From your initial question, it sounds like you are modifying a step template applied to your projects. I may be misinterpreting your requirements, but the step template feature allows you to “update” from the portal. When you make a change to a template, you can update the latest version to all projects using the template.

If you are still stuck here, please don’t hesitate to let me know.

Best regards,
Daniel

Thanks Daniel. I was able to get my scripts working after tweaking your example a bit. Appreciated!

Hi @snaulls,

Thanks for the update! I’m glad to hear you were able to get this working. :slight_smile:

Please don’t hesitate to get in touch at any time.

Best regards,
Daniel

Thanks Daniel. Be safe. Crazy times.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.