Adding the same process step to multiple projects quickly

Is there a way to quickly add the same step to multiple projects?


Is there a way to tell Octopus to run one ‘global’ step before a particular set of projects?

Thank you.

Greetings EliKol! Using the UI, you are able to clone steps to other projects, though it is one at a time. Using the API, it is possible to clone a step to multiple projects at once. Below is a PowerShell script that copies ALL steps from one project to another, but gives you an idea of how it can be done.

For the second question, I’m wondering if the Deploy a Release step might work for you in that you could deploy a release from one project before continuing on with another. I suspect that’s not quite what you’re looking for, but I thought I’d let you know.

$OctopusServerUrl = "https://YourOctoServer"
$ApiKey = "API-YourAPIKey"

# Call the API to update
$baseProject = (Invoke-RestMethod -Method "get" -Uri "$OctopusServerUrl/api/projects" -Headers @{"X-Octopus-ApiKey"="$ApiKey"}).Items | Where-Object {$_.Name -eq "WingtipToys"}
$deploymentProcess = Invoke-RestMethod -Method "get" -Uri ("$OctopusServerUrl/api/deploymentprocesses/{0}" -f $baseProject.DeploymentProcessId) -Headers @{"X-Octopus-ApiKey"="$ApiKey"}

$targetProject = (Invoke-RestMethod -Method "get" -Uri "$OctopusServerUrl/api/projects" -Headers @{"X-Octopus-ApiKey"="$ApiKey"}).Items | Where-Object {$_.Name -eq "Clone test"}

$targetProjectProcess =  Invoke-RestMethod -Method "get" -Uri ("$OctopusServerUrl/api/deploymentprocesses/{0}" -f $targetProject.DeploymentProcessId) -Headers @{"X-Octopus-ApiKey"="$ApiKey"}

$targetProjectProcess.Steps = @()

# Replace the id guids
foreach ($step in $deploymentProcess.Steps)
    $actions = @()

    foreach ($action in $step.Actions)
        $newAction = $action

        $actions += $newAction

    $newStep = $step
    $newStep.Actions = $actions
    $targetProjectProcess.Steps += $newStep

# Convert the object into JSON
$jsonBody = $targetProjectProcess | ConvertTo-Json -Depth 10

# Call the API to update
Invoke-RestMethod -Method "put" -Uri ("$OctopusServerUrl/api/deploymentprocesses/{0}" -f $targetProject.DeploymentProcessId) -Body $jsonBody -Headers @{"X-Octopus-ApiKey"="$ApiKey"}