考虑以下 Azure yaml 管道和模板,它们使用convertToJson函数将对象参数转换为 json 字符串:
parameters:
- name: foo
type: string
default: 'b"ar'
trigger: none
pool:
vmImage: 'ubuntu-latest'
variables:
- name: foo
value: 'b"ar'
steps:
- checkout: none
- template: /pipelines/steps/set-settings.yaml
parameters:
settings:
fooLiteral: 'b"ar'
fooParameter: ${{ parameters.foo }}
fooCompiledVariable: ${{ variables.foo }}
fooRuntimeVariable: $(foo)
模板/pipelines/steps/set-settings.yaml:
parameters:
- name: settings
type: object
steps:
- script: |
echo $SETTINGS
displayName: 'Display settings'
env:
SETTINGS: ${{ convertToJson(parameters.settings) }}
运行管道时,为什么除了 之外所有值都会得到正确转义fooRuntimeVariable
?