如何将参数值与Azure yaml管道中的字符串进行比较



定义为-的参数

parameters:
- name: deploy_images
displayName: Publish images to Project Repository?
type: string
default: NO
values:
- sandbox
- dev
- production

然后以下条件失败-

condition:  and( ne(${{ parameters.deploy_images }}, 'NO'), eq(${{ parameters.build_image }}, True))

错误-##[error]无法识别的值:"sandbox"。位于表达式中的位置9:和(ne(沙盒,NO(,eq(True,True((。有关更多帮助,请参阅https://go.microsoft.com/fwlink/?linkid=842996

在表达式周围提供单引号:

condition:  and( ne( '${{ parameters.deploy_images }}', 'NO'), eq(${{ parameters.build_image }}, True))

还要确保"NO"实际上在值中,并且您允许此参数(在它在我的环境中工作之前,我必须添加它(:

parameters:
- name: deploy_images
displayName: Publish images to Project Repository?
type: string
default: NO
values:
- sandbox
- dev
- production
- NO

{{如果eq('parameter.xxx',str}}或{如果eq(parameter.xxx,str(}总是失败,我必须使用布尔

这对我有效:eq(parameters['deploy_images'], 'sandbox')

我必须在模板中使用condition表达式才能使其工作。

工作模板:

- job:
condition: eq(variables['location'], 'ea')
steps:
- template: 'myTempl.yml'
parameters:
parm1: 'blah'

无法按预期工作的模板:

- ${{ if eq(variables.location, 'ea') }}:
- job:
steps:
- template: 'myTempl.yml'
parameters:
parm1: 'blah'

失败模板中的条件为false,即使值相同。

最新更新