If you're passing $HELM_SET
as a single string encoding multiple arguments, you cannot pass it as-is to a command.
Instead, you'll need to parse this string into an array of individual arguments.
In the simplest case, using the unary form of the -split
operator, which splits the string into an array of tokens by whitespace:
helm upgrade --install myrelease -n dev my_service.tgz (-split $HELM_SET)
However, if your arguments include quoted strings (e.g. --set config.spring="v 1"
), more work is needed, because the quoted strings must be recognize as such, so as not to break them into multiple tokens by their embedded whitespace:
# Note: Use of Invoke-Expression is safe here, but should generally be avoided.
$passThruArgs = (Invoke-Expression ('Write-Output -- ' + $HELM_SET -replace '\$', "`0")) -replace "`0", '$$'
helm upgrade --install myrelease -n dev my_service.tgz $passThruArgs
See this answer for an explanation of this technique.
If you control the invocation of your script, a simpler solution is available:
As Santiago Squarzon points out, you can use the ValueFromRemainingArguments
property of a parameter declaration to collect all arguments (that aren't bound to other parameters):
param
(
[Parameter(ValueFromRemainingArguments)]
$__passThruArgs # Choose an exotic name that won't be used in the actual arguments
)
helm upgrade --install myrelease -n dev my_service.tgz $__passThruArgs
Instead of passing the pass-through arguments as a single string, you would then pass them as individual arguments:
./yourScript.ps1 --set config.vali=x --set config.spring=v1