- Replace
<YourOctopusUrl>
with the URL of your Octopus server. - If you configured your Octopus server to not run at the root of the URL, replace
<YourOctopusVDirIfAnyOtherwiseJustBlank>
with the virtual directory you configured, otherwise remove it. - Replace
<YourOctopusApiKey>
with your API Key, see How to create an API Key for instructions. - Replace
<TheStepTemplateToFindAndUpdate>
with the name of the step template you want to update. - Run the script!
- After the script has completed (successfully :fingerscrossed:), go to
Library -> Step Templates ->
` -> Usage and update all the projects that use the step template.
Last active
July 14, 2016 00:07
-
-
Save hnrkndrssn/be0b2f1694b68ec893ea9e031e84b210 to your computer and use it in GitHub Desktop.
Updating a step template in Octopus to the latest version from the Octopus Deploy Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$octopusBaseUrl = "<YourOctopusURL>" | |
$octopusVdir = "<YourOctopusVDirIfAnyOtherwiseJustBlank>" | |
$octopusApiKey = "<YourOctopusApiKey>" | |
$headers = @{ "X-Octopus-ApiKey" = $octopusApiKey } | |
$libraryUrl = "http://library.octopus.com/api/step-templates" | |
$templateNameToFind = "<TheStepTemplateToFindAndUpdate>" | |
$octopusTemplates = Invoke-RestMethod -Uri "$octopusBaseUrl$octopusVdir/api/actiontemplates" -Headers $headers | |
$oldTemplate = $octopusTemplates.Items | ? { | |
$_.Name -eq $templateNameToFind | |
} | |
if ($oldTemplate) { | |
Write-Host "Found old template for $templateNameToFind" | |
$libraryTemplates = Invoke-RestMethod -Uri $libraryUrl | |
$newTemplate = $libraryTemplates | ? { $_.Name -eq $templateNameToFind } | |
if ($newTemplate) { | |
Write-Host "Found new template for $templateNameToFind" | |
$updatedTemplate = @{ | |
Name = $newTemplate.Body.Name; | |
Description = $newTemplate.Body.Description; | |
ActionType = $newTemplate.Body.ActionType; | |
Version = $newTemplate.Body.Version + 1; | |
Properties = $newTemplate.Body.Properties; | |
Parameters = $newTemplate.Body.Parameters; | |
} | |
Write-Host "Updating existing step template $templateNameToFind to latest version" | |
Invoke-RestMethod -Uri "$octopusBaseUrl$($oldTemplate.Links.Self)" -Method Put -Headers $headers -Body ($updatedTemplate | ConvertTo-Json -Depth 999) | |
} else { | |
Write-Host "Failed to find a step template named $templateNameToFind in the Octopus Library" | |
} | |
} else { | |
Write-Host "Failed to find a step template named $templateNameToFind in Octopus" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment