我正在努力根据所选变量获得正确的条件。我的管道:
parameters:
- name: versionTag
displayName: After the tagging, should we do a patch, minor or major version update?
type: string
default: patch
values:
- patch
- minor
- major
- script: echo you want to do a patch version bump
condition: eq(variables.versionTag, 'patch')
- script: echo you want to do a minor version bump
condition: eq(variables.versionTag, 'minor')
当我运行管道时,它只是说:“由于条件评估而跳过步骤”,即使我在启动管道时选择“补丁”。
我也尝试过:
- ${{ if eq(variables['versionTag'], 'patch') }}:
- script: echo "you want to do a patch version bump"
- ${{ if eq(variables['versionTag'], 'minor') }}:
- script: echo "you want to do a minor version bump"
它给出相同的输出。
有什么建议吗?
您正在使用参数,但在条件或
{{ if }}
语句中您引用了变量。
您应该使用 模板表达式语法 来引用参数 - 在本例中,(
${{ parameters.versionTag }}
.
使用条件:
steps:
- script: echo you want to do a patch version bump
condition: eq('${{ parameters.versionTag }}', 'patch')
displayName: 'Patch version bump'
- script: echo you want to do a minor version bump
condition: eq('${{ parameters.versionTag }}', 'minor')
displayName: 'Minor version bump'
使用
{{ if }}
语句:
steps:
- ${{ if eq(parameters.versionTag, 'patch') }}:
- script: echo you want to do a patch version bump
displayName: 'Patch version bump'
- ${{ if eq(parameters.versionTag, 'minor') }}:
- script: echo you want to do a minor version bump
displayName: 'Minor version bump'