Hi all, I’m trying to do a deploy via powershell, via the API but this has complicated things a lot and I’m hoping for a workaround.
When I do the appropriate post, it requests the internal ids for ReleaseId, EnvironmentId and SpecificMachineIds, like this:
$json=Invoke-WebRequest -uri “http://myinstance.octopus.com/api/deployments?apikey=API-QWERTYUIOP” -Method POST -Body $body
This works, but I want to be able to do this with the actual names, not the ids. Is this possible?
If not, what’s the simplest way to get the ids via the API based on the field names instead?
I can find the Name based on the id, is there a way to do the reverse perhaps?
Thanks for reaching out!
There are a few ways to get this done:
Octoposh is an open source Powershell module for Octopus which has a few cmdlets that can help you look for things by their name, like
Get-OctopusEnvironment -Name Production,
Get-OctopusRelease -version 1.0.0 and
Get-OctopusMachine -name MyVM. All of those will return an object which will have an
ID property that you can later on use in your
Octoposh site: http://octoposh.net/
Octoposh wiki: https://github.com/Dalmirog/OctoPosh/wiki
Using the raw API to get the resources and filter by name
Code will say more than words in this case: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Deployments/DeployExistingReleaseToSpecificSingleMachine.ps1
Hope that helps!
Thanks Dalmiro, nice repo there, I’ll be referring to it quite a bit I expect.