KeyNotFoundException for an unspecified parameter in a custom Step Template in C#

zaengi's Avatar

zaengi

19 Jan, 2018 05:20 PM

Given a custom C# Step Template with several Parameters, defined as "Single-Line TextBox".
None of These Parameters has a Default value given - but even if they had it wouldn't prevent this error.

When accessing the dictionary from the script code using Octopus.Parameters["Exclude"] a KeyNotFoundException is thrown (Octopus v4.1.9).

My analysis from the Tentacle "Work" directory shows, that the file "Variables.json" does NOT contain step parameters which aren't given or empty.
The "Exclude" variable was missing!
After I specified some spaces as value, it showed up (see example below).

"Octopus.Action.RunOnServer": "false",
"Path": "#{IIS.Website.Path}",
"Octopus.Action.Template.Id": "ActionTemplates-122",
"Include": "NLog\\.|web\\.",
"Exclude": " ",

I consider this a bug, because a pre-defined step parameter can't be omitted in the dictionary, and if unspecified it probably should have a null-value assigned.

By now,the only workaround is to check for existence, e.g. using Octopus.Parameters.TryGetValue("Exclude", out exclude)

PS:
Is there a config Setting on the tentacle to keep the "Work" Directory for easier debugging your buggy deployment tool? ;-)

  1. Support Staff 1 Posted by Tom Peters on 22 Jan, 2018 01:11 AM

    Tom Peters's Avatar

    Hi,
    Thanks for getting in touch.

    I agree with you, this feels like a bug to me as well. I've raised an issue for it here, which you can use to track our progress with addressing the bug.

    In the meantime, I would suggest sticking with the workaround that you have suggested (using TryGetvalue in your script).

    For reference, there are some variables you can configure in your project to help debug which variables are present at execution time. You can read about them here.

    Thanks for reporting this issue!

    Regards,
    Tom

  2. 2 Posted by zaengi on 11 Jun, 2018 10:46 AM

    zaengi's Avatar

    Hey,
    you seem to not gonna change this behavior, will you?

    Is it at least documented in the Online-Help-Pages meanwhile?

  3. Support Staff 3 Posted by Tom Peters on 18 Jun, 2018 03:34 AM

    Tom Peters's Avatar

    Hi,

    We intend to address this issue at some point in the future. We have a lot of other work we are doing at the moment and have not yet had time to look into this in more detail.

    Regards,
    Tom

Reply to this discussion

Internal reply

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

Attaching KB article:

»

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