如何在 azure devops 管道的起始变量中创建 yaml 切换?

How to create a toggle on yaml in the starting variables of the azur devops pipeline?

我有一个管道使用一个可以采用多个硬编码值的变量。此变量在管道启动屏幕上可用,用户必须填写它。因此,会出现拼写错误并且管道无法运行。我可以将此变量设置为切换开关,以便用户无需输入值,而是从可用值列表中选择它吗?

您不能对变量执行此操作,但可以用于此目的 runtime parameters

例如:

parameters:
- name: image
  displayName: Pool Image
  type: string
  default: ubuntu-latest
  values:
  - windows-latest
  - vs2017-win2016
  - ubuntu-latest
  - ubuntu-16.04
  - macOS-latest
  - macOS-10.14

trigger: none

jobs:
- job: build
  displayName: build
  pool: 
    vmImage: ${{ parameters.image }}
  steps:
  - script: echo building $(Build.BuildNumber) with ${{ parameters.image }}

产生: