I’m calling an object parameter value in my az keyvault secret set
script and it works fine except when a secret value starts with a special character like #
for example.
parameters:
- name: info
displayName: Information
type: object
default:
- subName: Sub1
kvs:
- kvName: kv1
secretName: test-secret
secretValue: #testvalue
- name: infoCategory
displayName: Select which category you wish to you
type: string
default: Schema
values:
- Cat1
steps:
- ${{ each sub in parameters.info }}:
- ${{ each keyvault in sub.kvs }}:
- task: AzureCLI@2
displayName: Updating ${{keyvault.secretName}} in ${{keyvault.kvName}}
inputs:
azureSubscription: ${{sub.subName}}
workingDirectory: $(OPT_DIR)
scriptType: 'bash'
scriptLocation: 'inlineScript'
serviceConnectionName: ${{sub.subName}}
inlineScript: |
# Case statements for schemas needed to be stored, encrypted or both
case ${{ parameters.spmWlpHashStore }} in
Cat1)
# Storing schema password
az keyvault secret set --name ${{keyvault.secretName}} --vault-name ${{keyvault.kvName}} --value ${{keyvault.secretValue}} --content-type 'content' --expires ${{parameters.expiryDate}}
echo "$expiryDate"
;;
The line where I run the az keyvault secret set
will throw an error
–value requires a value
when my ${{keyvault.secretValue}}
refers to a value that start with a special character. But it works for every other password I tried that starts with a number or a letter.
I tried putting it in double quotes "${{keyvault.secretValue}}"
, single quotes '${{keyvault.secretValue}}'
. I tried creating a variable and assigning the value to the variable and then calling that variable in the az keyvault secret set
command, but nothing worked
3
Answers
Instead of:
Do:
Example
See also Cannot set ENV variable in azure pipeline with value from other step.
I can reproduce the same issue as yours when using the similar YAML sample.
To solve this issue, you need to change the following two Points.
1.You need to add single quote to the
secretValue
in Parameters. If the value contains#
and without single quote , it will be commented.For example:
2.You need to add single quote to the
${{keyvault.secretValue}}
in Azure CLI task.For example:
Here is the YAML sample:
Result:
Try below: single quotes + double quotes