API - Channels & Retention Policy

I’m continuing to work on scripting adding a new environment, a channel to an existing project, a new lifecycle and then create a copy of the variables (both in local variables and variable sets) assigned to the previous environment and scope them to the new environment.

I’m doing this via powershell. Two things I’m stuck on (I haven’t gotten to the variables yet).

  1. I’m looking at Lifecycles and retention policies. I’ve found this example: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/Octopus.Client/PowerShell/Lifecycles/CreateLifecycleWithPhase.ps1, however when I use the syntax there, it can not (with 3.3.6) find “new” and so that it fails. I’ve looked at LifeCycle.ReleaseRetentionPolicy and it expects a Octopus.Client.Model.RetentionPeriod, so it appears that either I’m stuck creating one manually, or finding one to borrow from, or I’m missing something.
  2. I’m trying to do a find on Channels so I can rerun the script and not error out with a duplicate channel. In trying to do a repository.Channels.findByName(“Blah”) I’m getting a message Exception calling “FindByName” with “1” argument(s): “” except that when I look at autocomplete in Powershell, that is exactly what it is looking for. Knowing that channels are also project specific, I’m also not completely clear on whether I’m supposed to be passing in the string for the projectName or channelName. It would seem both would be necessary, but if there isn’t a method… I also did try “findOne” using the ChannelResource I use to create the channel, however that also did not find the channel and then fails because it exists.

Any help?


Sorry for the huge delay here. Somehow we missed this ticket from the queue :frowning:

  1. I haven’t tested the script for a while, but I did recently wrote these 2 examples using Octoposh. You might wanna take a look at: How to create a Lifecycle and How to modify a lifecycle

They shouldn’t be too hard to understand/reverse engineer. Let me know if you need help with them

  1. You are totally right here. I’ll bring this up to the devs and get back to you way sooner than in this reply.


Hi again,

About point (2), I got some feedback from the dev team:

  • Channels.FindbyName() has been removed from Octopus.client in one of the latest versions of the Development branch. You’ll see it once we ship 3.4

  • To get the channels, you need to do it from the Projects repository this way: Repository.Projects.GetChannels(project). Then filter out by name.

Hope that helps,

Great. Thanks for the information. Now I just need to find time to get back to this. :slight_smile:

Mike Peterson
IT Deployment Specialist
Preventice Solutions Group

2765 Commerce Dr NW, Ste 220
Rochester, MN 55901
Office: 507-218-3053
Mobile: 507-251-2315

Preventice Services, LLC and Preventice Technologies, Inc. are part of the Preventice Solutions Group of companies and are independent, wholly owned subsidiaries of Preventice Solutions, Inc.

This message contains confidential information and is intended only for the sole use of the addressed recipient(s). If you are not one of these recipients you should not disseminate, distribute or copy this e-mail. Please notify the designated recipients immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmissions cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender, therefore, does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version.