Resurrecting the "Reordering steps using powershell" thread

In the effort to improve release throughput we’re running a pilot to move SQL deployments from a dedicated tentacle to a pool of workers. As part of the conversion we’re disabling project steps based on the old template and creating new project steps based on the new deployment template for our projects. Ideally we’d like the new project step to be immediately after the disabled step, so the deployment order is preserved. Given the number of projects in scope (literally hundreds) doing this manually is not practical.

The one thread I found on this (“Reordering steps using power shell”) doesn’t point towards a solution; however I’m curious if there’s a mechanism for this now. Thanks.

Hey there Shannon!

I’ve done something similar to this recently, but it ends up being VERY context dependent on your steps. It’s not exactly the cleanest, but it works! I’m happy to share the bones of the script that I wrote, which can at least point you in the right direction of how to start approaching this. Can you tell me some more about your current template step and what you’re hoping to move to? That’ll help define the structure of how it would be scripted out.

The broad strokes of how it works:

  • Iterate through your projects and their deployment processes, looking for those that have deployment steps matching the type expected
  • Create your new step, pulling over any relevant data from the prior step and setting sane defaults for anything that isn’t a 1:1 match between steps
  • Add the newly built step in after the index of the previous step, then disable the previous step
  • POST the new deployment process for the project to update it with the new values

Hi Cory -

Thanks for the quick response! Essentially I coded the process (disable the old step, create the new one based on the new template and copied over the old step settings); however when I add the new step it always puts it at the end ( I want it after the disabled step). Any coding samples would be super helpful.

Much appreciated!


Hey Shannon!

The basic chunk where things are getting handled looks like this (inside of a foreach ($step in $deploymentProcess.steps)):

# Convert array to a collection to allow for inserts
$stepIndex = [array]::IndexOf($steps, $step)
$stepCollection = {$deploymentProcess.Steps}.Invoke()
$stepCollection.Insert(($stepIndex + 1), $newStep)

# Convert back to array to incorporate to deployment process
$stepCollection | Set-Variable stepArray
$deploymentProcess.Steps = $stepArray

# Create JSON payload
$deploymentProcessAddPayload = $deploymentProcess | ConvertTo-Json -Depth 10

If you have any more questions, don’t hesitate to let me know, this is specifically the ordering logic I used.

Hi Cory -

VERY much appreciate the example! I was able to adapt it to position the new steps exactly where I wanted. Super helpful. Thanks again!

Excellent! Glad it’s working, don’t hesitate to shout if you need a hand with anything else :+1:

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