IIS Bindings Enabled Custom Expression Not Working

lisa.pierson's Avatar


16 Feb, 2017 08:08 PM

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

  1. Support Staff 1 Posted by Dalmiro Grañas on 17 Feb, 2017 02:23 PM

    Dalmiro Grañas's Avatar


    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.



  2. 2 Posted by lisa.pierson on 17 Feb, 2017 02:34 PM

    lisa.pierson's Avatar

    Here you go!

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

  3. Support Staff 3 Posted by Dalmiro Grañas on 20 Feb, 2017 06:25 PM

    Dalmiro Grañas's Avatar

    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/suggestio...


  4. 4 Posted by lisa.pierson on 20 Feb, 2017 07:15 PM

    lisa.pierson's Avatar

    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.

  5. Support Staff 5 Posted by Dalmiro Grañas on 21 Feb, 2017 09:45 PM

    Dalmiro Grañas's Avatar

    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.


  6. 6 Posted by lisa.pierson on 22 Feb, 2017 06:19 PM

    lisa.pierson's Avatar

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

  7. Support Staff 7 Posted by Dalmiro Grañas on 22 Feb, 2017 07:33 PM

    Dalmiro Grañas's Avatar

    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 :)

  8. 8 Posted by lisa.pierson on 22 Feb, 2017 08:58 PM

    lisa.pierson's Avatar

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

  9. Support Staff 9 Posted by Dalmiro Grañas on 23 Feb, 2017 04:49 PM

    Dalmiro Grañas's Avatar

    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,

  10. Paul Stovell closed this discussion on 30 May, 2017 12:34 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac