Skip to content

Instantly share code, notes, and snippets.

@DamianMac
Last active April 6, 2016 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamianMac/00c4b7ccac698b200f13 to your computer and use it in GitHub Desktop.
Save DamianMac/00c4b7ccac698b200f13 to your computer and use it in GitHub Desktop.
Query and Update Octopus Deploy projects and lifecycles
$server = " http://yourserver/" #your octopus server
$apiKey = "API-YOURAPIKEY" #you'll need to generate an API
$command = $($server + "/api/projects")
$projects = Invoke-RestMethod -Method Get -Uri $command -Header @{"X-Octopus-ApiKey"=$apiKey}
$projects.Items | Format-Table Id, Name, lifecycleId
$command = $($server + "/api/lifecycles")
$lifecycles = Invoke-RestMethod -Method Get -Uri $command -Header @{"X-Octopus-ApiKey"=$apiKey}
$lifecycles.Items | Format-Table Id, Name
$server = " http://yourserver/" #your octopus server
$apiKey = "API-YOURAPIKEY" #you'll need to generate an API
$command = $($server + "/api/projects/Projects-106") #use the project ID from the earlier query as the URL
$project = Invoke-RestMethod -Method Get -Uri $command -Header @{"X-Octopus-ApiKey"=$apiKey}
$project.LifecycleId = "Lifecycles-120" #use the lifecycle ID from the earlier query and change this to the one you want
$body = $project | ConvertTo-Json
$new = Invoke-RestMethod -Method Put -Uri $command -Body $body -Header @{"X-Octopus-ApiKey"=$apiKey}
#run this then run the previous query and you should see it all fixed up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment