Hi,
We currently have 8 projects that are effectively clones of each other just using variables to distinguish which nuget packages to select.
A problem we have is keeping the 8 projects aligned , when we add a step from a template into a project and test we then have the long process of making sure the remaining 8 (and growing) projects have the same steps in the same order…
Now I’ve wrote some powershell to clone the steps from 1 project into another , I’m wondering if anyone could advise if this would work as i intend , all of the steps are from step templates and contain NO project specific information
it backups the existing steps of the project you are cloning to and exports these
it then removes all the steps from the target project
it then adds all the steps / actions from the clone project into the target project and updates the process
I have tested and from what i can see it works and i can update the step template versions etc
Thanks
Kris
script
$copyfromproject = Read-Host “please enter the master project to copy from”
$copytoproject = Read-Host “please enter the project to copy to”
$fromprojectId = ($repositry.Projects.FindByName("$copyfromproject")).Id
$toprojectId = ($repositry.Projects.FindByName("$copytoproject")).Id
$fromproject = $repositry.Projects.Get($fromprojectId)
$fromprocess = $repositry.DeploymentProcesses.Get($fromproject.DeploymentProcessId)
$toproject = $repositry.Projects.Get($toprojectId)
$toprocess = $repositry.DeploymentProcesses.Get($toproject.DeploymentProcessId)
$backup = $repositry.DeploymentProcesses.Get($toproject.DeploymentProcessId)
$backup | Export-Clixml "c:\test$copytoproject.xml"
foreach($step in $($toprocess.Steps))
{
$toprocess.Steps.Remove($step)
}
$repositry.DeploymentProcesses.Modify($toprocess)
$toproject = $repositry.Projects.Get($toprojectId)
$toprocess = $repositry.DeploymentProcesses.Get($toproject.DeploymentProcessId)
foreach($steps in $fromprocess.Steps)
{
$step = New-Object Octopus.Client.Model.DeploymentStepResource
$step.Name = $steps.Name
$step.Condition = $steps.Condition
$step.StartTrigger = $steps.StartTrigger
$step.RequiresPackagesToBeAcquired = $steps.RequiresPackagesToBeAcquired
$step.SensitiveProperties.Add("$($steps.SensitiveProperties.Keys)","$($steps.SensitiveProperties.Values)")
$step.Properties.Add("$($steps.Properties.Keys)","$($steps.Properties.Values)")
foreach($action in $steps.Actions)
{
$keys = $action.Properties
$scriptAction = New-Object Octopus.Client.Model.DeploymentActionResource
$scriptAction.ActionType = $action.ActionType
$scriptAction.Name = $action.name
$scriptAction.Channels.Add($action.Channels)
$scriptAction.SensitiveProperties.Add("$($action.SensitiveProperties.Keys)","$($action.SensitiveProperties.Values)")
foreach($key in $keys.GetEnumerator())
{
$scriptAction.Properties.Add("$($key.Key)", "$($key.value)")
}
$step.Actions.Add($scriptAction)
}
$toprocess.Steps.Add($step)
}
$repositry.DeploymentProcesses.Modify($toprocess)