jhong
(jhong)
19 October 2015 01:00
1
HI
is there an example to create a new lifecycles? (with powershell)
I’ve tried following but get 400 bad request
$OctopusAPIKey = “”
$header = @{ “X-Octopus-ApiKey” = $OctopusAPIKey }
$body = @{
Name = “New Lifecycle”
}
$URI = “https://builder01:8080/api/lifecycles ”
$json = invoke-restMethod -Method POST -Headers $header -Body (convertto-json $body) -uri $URI
Dalmiro
(Dalmiro Grañas)
19 October 2015 18:42
2
Hi,
Thanks for getting in touch. I’d recommend you to use the Octopus.client instead of the REST API to create lifecycles. Working with .NET objects makes this a lot easier and less error prone. Here’s a script that uses the Octopus.client library to create and configure a lifecycle: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/Octopus.Client/PowerShell/Lifecycles/CreateLifecycleWithPhase.ps1
Hope that helps!
Dalmiro
jhong
(jhong)
19 October 2015 22:18
3
HI Damiro
Thanks for the reply
I have tried it but get an error msg. I have tested it using the latest octo.client.dll downloaded using nuget.
====
Unable to find type [Octopus.Client.Model.RetentionPeriod]. Make sure that the assembly that contains this type is loaded.
At C:\Users\app\Desktop\Untitled1.ps1:34 char:1
jhong
(jhong)
20 October 2015 01:16
4
BTW, I need to run “create lifecycle” from non windows machine, if you could post example for REST API that would be much appreciated too.
Thanks
Dalmiro
(Dalmiro Grañas)
22 October 2015 13:14
5
Hi,
Here’s a Powershell snippet that only uses the REST API: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Lifecycles/CreateLifecycle.ps1
Take a moment to read the whole request body, as it is quite big, but also pretty self-explanatory. If there’s something you don’t understand, let me know.
Dalmiro