Use custom expression to toggle setting

Hi there,

My scenario:
1.- My project has 2 channels: hard and soft.
2.- When deploying through the hard channel, I want my Custom install directory to be purged.
3.- When deploying through the soft channel, I want my Custom install directory not to be purged.

The binding syntax documentation ( ) says that For settings that support variables but aren’t text (such as drop downs or checkboxes), a button is displayed to toggle custom expression modes.

How can I use custom expressions for this? I.e. ideally I would like to add a custom expression to the Purge setting that says the equivalent of:

Is that supported through some syntax?

Alternatively, I’ve tried adding a Pre-deployment script that sets an Octopus variable IsHardDeployment and uses it in the custom expression like this:
#{Octopus.Action[deploy stuff].IsHardDeployment}

That doesn’t appear to work either.

Any suggestions welcome!


Thanks for reaching out. In this case you need to:

  1. Create two variables with the same name (lets call it Purge) and the values true & false. Then scope each to the corresponding channel. See attached screenshot.

  2. Then just use that variable on the Custom Expression field as shown on the 2nd screenshot.

Hope that helps,

That seems to work brilliantly, thank you!


A follow-up in this: I’m finding that when I clone my project that has this Purge variable defined, the Scope details are lost!

It looks like during the clone it doesn’t transfer the Channel details across properly. Note that in my case the Purge=true variable was scoped to 2 different Channels and in the screenshot attached you can see there is a comma still showing…

Is this a known/new bug, or am I missing something?

Using Octopus 3.2.17.


Upgraded our server to 3.3.1 to see if that would resolve it, but the bug is still present.

Hi Martin,

Thanks for the heads up of that bug. I’ve created a github issue to get it fixed:


Hi Dalmiro,

Thanks for that. What is the estimated fix time for this bug?

In the meantime, how can I use Octopus.Client.dll in PowerShell to get my cloned project’s channel IDs so I can add the missing ones myself? I.e:

$repository = new-object Octopus.Client.OctopusRepository $endpoint
# How do I get a channel ID from the name of a channel in my project?
$repository.Channels.Get([the channel ID])
$var.Scope.Add([Octopus.Client.Model.Scopefield]::Channel, (New-Object Octopus.Client.Model.ScopeValue("[the channel ID]")))


Hi Martin,

We’ve taken this one out of our backlog and added it to our queue, meaning it should be out in the next release or the one after, unless of course the underlying issue is bigger than we estimated.

The logic to fix this issue is a bit more complicated than just adding the missing scope to the variable using the Octo client and I’d definitely recommend you to wait until the fix instead of scripting your way around it. For the time being please try to manually add the scope to the variable from the web portal.

Best regards,