IIS Bindings Enabled Custom Expression Not Working

Lisa Pierson's Avatar

Lisa Pierson

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

    Hi,

    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.

    https://octopus.com/docs/how-to/how-to-turn-on-variable-logging-and...

    Thanks,
    Dalmiro

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

    Regards,
    Dalmiro

  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.

    Thanks,
    Dalmiro

  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,
    Dalmiro

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • add_binding.png 43.2 KB
  • project_variables.png 8.17 KB
  • variables_in_log.png 73.1 KB
  • error.png 73.3 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? 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

Recent Discussions

25 Apr, 2017 04:28 PM
25 Apr, 2017 04:08 PM
25 Apr, 2017 04:04 PM
25 Apr, 2017 03:43 PM
25 Apr, 2017 03:39 PM

 

25 Apr, 2017 03:31 PM
25 Apr, 2017 03:28 PM
25 Apr, 2017 03:11 PM
25 Apr, 2017 02:54 PM
25 Apr, 2017 02:27 PM
25 Apr, 2017 01:17 PM