New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step template parameters not included in variable dictionary unless a value is provided in a step #4191

TomPeters opened this Issue Jan 22, 2018 · 0 comments


None yet
1 participant

TomPeters commented Jan 22, 2018

To reproduce:

  1. Set up a step template, which has a single parameter. Don't specify a default value and make the type "Single-line text box". Make the step a C# script and in the body of the script, access the parameter value by using Octopus.Parameters["my-parameter-name"]
  2. Use the step template in a deployment process. Leave the parameter value alone, don't enter anything in the field and do not override its value with anything.
  3. Deploy the project.

At runtime, you will get an error like ERROR: Script execution failed. [KeyNotFoundException] The given key was not present in the dictionary.

Since the variable value was not explicitly specified as part of the step, it is not included in the variable collection during deployment. If you try to do the same thing in PowerShell, you will end up with a null value, due to the differences between the C# dictionary and the PowerShell one.

As a workaround, you can use .TryGetValue or .Contains in the C# script to handle the case where the variable has not been defined.

There may be people that are currently checking whether the variable exists in the dictionary as part of their scripts, so any changes here could potentially break existing deployments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment