We have a deployment script in DevOps that uses the “az apim nv create” command to create/update an APIM named value. We use this the create a named value that contains the Access key of an Azure Function.
We use this command :
az apim nv create --display-name $NamedValueName --named-value-id $NamedValueName --resource-group $ResourceGroupName --service-name $APIMName --value $accesskey --secret true --tags key function auto
This is all working well UNLESS if the access key of the function starts with a minus. If that is the case, we get the error “argument –value: expected one argument”.
Probably related to the way we pass the variable to the function parameter.
How can we avoid this, what is the safest way to pass a variable to a function parameter?
Regards,
Sven Peeters
3
The variable value is correctly passed actually, the error is caused by azure cli, it doesn’t accept the minus started value in the command.
It will report same error if you use hardcode -foo
in the command on local machine:
It works if value is not started with minus sign.
If you use the azure cli to create the name values, please consider to not use -
started value.
5
This is all working well UNLESS if the access key of the function starts with a minus. If that is the case, we get the error “argument –value: expected one argument”.
Based on your description, when the value contains minus character, it will show this error.
As the answer shared by Wade, the cause of the issue is that Azure Cli command doesn’t accept the minus started value.
To solve this issue, you can add --%
in your Azure CLI command and add double quote to value field(--value "$accesskey"
) to solve the issue.
For example:
az apim nv create --% --display-name $NamedValueName --named-value-id $NamedValueName --resource-group $ResourceGroupName --service-name $APIMName --value "$accesskey" --secret true --tags key function auto
Or you can use the following format to translate the value contains minus character.
--value `"$accesskey`"
For example:
az apim nv create --display-name $NamedValueName --named-value-id $NamedValueName --resource-group $ResourceGroupName --service-name $APIMName --value `"$accesskey`" --secret true --tags key function auto