Missing an argument for parameter .Specify a parameter of type 'System.String' and try again

I’ve created a step template to run a powershell script with arguments. An example of the script looks as follows:

.\foo.ps1 -arg $arg -arg1 $arg1

With arg and arg1 as parameters on the step template. I was under the impression that if no value for arg1 was given then $null would be used as its value in the step but i get the error in the title if I do this. I also tried setting a default value of both ‘$null’ and on another occasion ‘Default’ to see if that would work but unless I specified a value in the process step itself then I was met with the error. Am I missing something or is this expected behaviour? Surely a default value should at least work when no other argument is specified.

Hi Adam,

Thanks for getting in touch! Currently I’m unable to say precisely the issue here, though I would lean towards it being the expected behavior. Perhaps $null is being converted into an empty string. I would like to give it a test in my local instance (and maybe talk with my team about this) to see if we can find the cause. Would you be willing to provide the script itself so I can test it out?

I look forward to hearing back and getting to the bottom of this one!

Kind regards,

Kenny

Hi Kenneth,

I can provide the script no problem, i’ve attached the JSON of the exported step template here (4.4 KB). It’s actually to run a script against a docker container but the concept should be the same. As the issue seems more about OD itself than what the script does.

It’s worth pointing out that the issue isn’t that $null is being passed as a string but that nothing is being passed in the script. There is a different discussion on here that specifies $null is passed and goes on to explain how $null is different to an empty string so it would be weird if you’d changed that.

https://help.octopusdeploy.com/discussions/problems/53694-step-template-with-script-parameters-empty-variables-not-substitued

If an argument isn’t provided then the script at deploy time would look like:

.\foo.ps1 -arg $arg -arg1 -arg2 $arg2

So the issue at this point isn’t happening inside foo.ps1 but in the execute script itself.

This also doesn’t explain the behaviour of the default values when they are present.

My impression was either that

a) if nothing was provided -arg2 would be provided $null

or

b) a default value would be used if one was set in the step template, again this ends in no argument being provided if the argument isn’t set in the deployment process itself.

I’ve done a little more digging and have found some behaviour that seems to me to at least be misleading in the deployment process. If I create the step template with no default values specified and add that to a deployment process then go back and add the default values and update the process step I can see the following in the parameters list on the process step:

If i then click on the parameter it expands to show the following:

But as you can see here there is no option to save this. This is what made me think the empty value was using the “default” value. After creating a new process step using the step template I can see the parameter should not say “provide a value” at any time. Should the default values update with the process step? This is also the behaviour if you delete the default value, save and then view the parameters list later.

I must point out, this still doesn’t answer my question about $null when no value is present so I would still appreciate it being looked in to.

Thanks,
Adam

Hi Adam,

Thanks for following up and providing that additional information.

I’ve been able to reproduce the behavior where the default value for a parameter doesn’t display immediately within the step in the project. The expected behavior is that it should display the default value you’ve configured for the step template if no other value was provided in the step you’ve added to your project. This should also automatically populate the parameter during deployment.

I was running 2018.5.6 in my local instance, and after upgrading to latest (2018.5.7), this behavior is fixed - the default value is displayed in the step and gets passed into my step. Would you be able/willing to upgrade to latest and see if this fixes the issue in your case?

I look forward to hearing back!

Best regards,

Kenny

Hi Kenneth,

Thanks for getting back to me. I will upgrade our Octopus server this week and let you know. Do you have any information regarding the behaviour when no default and no value is supplied to a parameter? I was under the impression it should be $null but it throws the missing argument error.

Thanks,
Adam

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.