My countryCode参数为"myathlon是";,但在条件插入中评估parameters.countryCode时,我似乎总是得到null。
parameters:
- name: countryCode
default: '$(countryCode)'
steps:
- script: |
echo "this is the country code for the service ${{ parameters.countryCode }}"
- ${{ if eq(parameters.countryCode, 'myathlon-be') }}:
- script: 'echo i am belgium'
- ${{ if ne('parameters.countryCode', 'myathlon-be') }}:
- script: 'echo i am NL'
output:
Generating script.
Script contents:
echo "this is the country code for the service myathlon-be"
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /var/build/Ubuntu0101/_work/_temp/7793af00-16c0-4fb7-a2db-ce48bfe9151a.sh
this is the country code for the service myathlon-be
Finishing: CmdLine
Generating script.
Script contents:
echo i am NL
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /var/build/Ubuntu0101/_work/_temp/bc8cdeba-ca32-48b6-923a-ae49cf8c3dee.sh
i am NL
Finishing: CmdLine
感谢
如果countryCode
看起来像是一个变量,那么您可能会被以下事实所困扰:变量在任务执行之前进行了扩展,但在执行条件时不会进行扩展,因为条件需要在编译时出现。
作为测试,您可以从调用该模板的YAML中硬编码参数,并且您应该看到它按预期进行评估。
感谢james的回复。
我通过以不同的方式修复了它
定义参数"的值;countryCode";直接在build.yml中。然后选择参数"的值;countryCode";在main.yml.中