Using ActionTemplateResources with Octopus.Client

Is it possible to clone or re-use one of the runbook CommunityActionTemplates objects? I am using the Octopus.Client.dll to try and accomplish this.

For example, I would like to re-use the ‘SQL - Execute Script’ community action template. I’m able to retrieve the template but I’m not sure how to add it as a step to an existing runbook? It’s possible to read the value from the action template and then apply it to each setting on a new action object, but I’m wondering if there is some way to easily clone the template as it does through the interface.

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL, $OctopusAPIKey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$Project = $repository.Projects.FindByName('My Test Project')    
$ActionTemplate = $repository.ActionTemplates.FindByName('SQL - Execute Script')
$Runbook = $repository.Runbooks.CreateOrModify($Project,'My Runbook','Test Runbook Description')

$step = $Runbook.RunbookProcess.AddOrUpdateStep('StepOne')
$step.AddOrUpdateAction($ActionTemplate) | out-null


I’ve tried a few ways to do this and I can’t get anything to work.

Thanks so much for your thoughts!

Hi Ashton,

Thanks for getting in touch.

There’s no convenient option on the API to clone an individual step like this, but we have some examples in our REST API Samples repository that may help you find your way.

I believe this sample should help to fill in some gaps for you.

You’d need to emulate what our UI does, where we read from the action template and assign the relevant properties to the new step. It’s essentially looping over all the properties and actions (then properties within the actions) and assigning them from the template to the step.

Hope this helps. Let me know how you go.