IIS Bindings Enabled Custom Expression Not Working

I am trying to use a variable to determine whether or not an IIS Binding is enabled or disabled. Ultimately, I want to use an if expression. However, I am having an issue that even if my custom expression is simply a variable representing true or false and error is thrown. I have attached the IIS Binding, variable setup, log showing the variable values, and the error message.

There was conversation that was closed with the same issue. No resolution was posted: https://help.octopusdeploy.com/discussions/problems/46529-multiple-iis-bindings-for-some-environments


Thanks for reaching out! I just tested this really quick in 3.10.0 and it worked as expected on my end.

Could you please follow the instructions on the below doc and send me a full deployment log? That should help me figure out what’s going on on your end.



Here you go!

You will see in the log that I would like to eventually move to using if statements in the custom expression.

ServerTasks-64205.log.txt (57 KB)

Hi Lisa,

The problem here seems to be the binding with the && logic on it, which is not something we support at the moment. The only way to currently fake the && logic for variable replacement is by using nested IF statements like #{if var1}{if var2}true{/if}{/if}#

The other variable with the single #{True} variable looks ok. I tested it on my end and it looks exactly like yours in the log:

07:29:20   Verbose  |       [Octopus.Action[Deploy test website].IISWebSite.Bindings] = '[{"protocol":"http","ipAddress":"*","port":80,"host":"","thumbprint":"","requireSni":false,"enabled":true},{"protocol":"http","ipAddress":"*","port":"81","host":"","thumbprint":"","requireSni":false,"enabled":"#{True}"}]'

I’ve created a Uservoice suggestions to add support for && and || for variable replacements. Please try to drop by and leave some votes on it if you’d like to see it implemented in the future: https://octopusdeploy.uservoice.com/forums/170787-general/suggestions/18397306-add-support-for-and-or-operators-for-variable-re


I updated all the statements to use the nested if as you recommended below and I’m still getting the same error. I’ve attached the log again.

ServerTasks-64980.log.txt (57 KB)

Hi Lisa,

Sorry I took some extra time to get back to you for this. It took me a fair amount of re-learning this feature that I haven’t used in a while :). In the meantime I even found a bug which made almost made me lose my mind for 2 straight hours: https://github.com/OctopusDeploy/Issues/issues/3200

I also learned that #{else} is not supported in Octostache, even though I was super sure it should work: https://github.com/OctopusDeploy/Issues/issues/1583

So, after a long session of testing, I came up with how your bindings should look like:

#{if Octopus.Action.TargetRoles == "build-server"}#{if Octopus.Environment.Name == "Local"}True#{/if}#{/if}

Another pro tip that I learned the hard way today is that the comparison value (what comes after the ==) is ultra case sensitive. So build-server is not the same as Build-Server and Local is not the same as local.

Let me know if the above works for you.


Thank you for all the time, blood, sweat, and tears you have put into investigating this for me. Hopef{kw

ServerTasks-65444.log.txt (56 KB)

Hi Lisa,

Looks like your message didn’t come in full. Sad to see those errors still there :(.

Is there any chance you can create a brand new test project and instead of using those 4-5 bindings all at once, try them one at a time so we can get the smallest possible way to reproduce this error.

Once you do that send me the same log with debug variables on from the clone project.

Looking forward to see those logs :slight_smile:

It seems to be breaking the first time it hits my if statements.

ServerTasks-65464.log.txt (217 KB)

Good news! I was able to reproduce this bug and I created a github issue for it: https://github.com/OctopusDeploy/Issues/issues/3213

To get you up and running, a possible workaround would be:

  1. Enable the Scripts in Package Steps feature feature in your IIS deploy step.

  2. On the “Pre deploy script step”, put the code on the below gist. It has to be on the Pre one or this workaround wont work. https://gist.github.com/Dalmirog/f62af1269603f7ce72a3e285d46e3ed1

  3. Set the custom expression of your IIS binding “enabled” field to just the single variable you created on the pre-deploy script(*). In my example that would be #{MyBindingVariable} (see attached screenshot)

Notes about the script:

  • In this line you’ll be setting the name of the variable that you’ll use in your binding’s “Enabled” field

  • These 2 lines set the conditonal logic for the variable.

Let me know if that helps,