17

For Azure DevOps Release pipeline, is it possible to create Dropdown list for custom variables?

So for below, if I wish to have dropdown values instead of single text value enter image description here

Patty
  • 451
  • 1
  • 4
  • 11

3 Answers3

23

If you are going to trigger the pipeline manually then you can make use of Runtime parameters in the Azure DevOps pipeline.

For Example:
In order to make OS image name selectable from a list of choices, you can use the following snippet.

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 # trigger is explicitly set to none

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

This results in the following.

result

More info on Runtime parameters can be found here. Hope this helps.

The only downside with this is that since we are specifying trigger as none we may not be able to integrate into an automatic pipeline. I've not yet tried it. Let me know if it works in an auto pipeline.

Note: The example and image shown here is fetched from azure DevOps documentation.

Mani
  • 5,401
  • 1
  • 30
  • 51
  • 1
    OP is asking about "Azure DevOps Release pipeline" which does not has YAML support. This solution can work for CI Pipeline – Karan Kaw Dec 20 '20 at 02:58
  • ADO pipelines have had release pipeline YAML support since 2019, though not for all features. https://devblogs.microsoft.com/devops/whats-new-with-azure-pipelines/ – james.garriss Oct 27 '22 at 17:53
3

As I know the dropdown value is not supported yet.

The custom variable in release pipeline is a key-value pair, the value should be one specific value instead of a dropdown list. The value could be single text value, could be true/false or other variable using format $(VarName) from variable group. But we can't pass a dropdown list as value to the variable.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • it would make sense in situations where you just want to present a simple interface to a customer in order to fill in the blanks for things. As an example there are hundreds of VM sizes in Azure a user could choose from, if we could have a variable whose value pulls from a collection, that would be make releases so much more customizable at release time. Is there a voting place for feature requests? or github issue we could create? – Jeff Patton May 07 '20 at 15:37
  • You can post the feature request [here](https://developercommunity.visualstudio.com/spaces/21/index.html), it's our user voice forum. – LoLance May 08 '20 at 01:04
  • @JeffPatton Also, according to your comment, may our new feature [runtime parameters](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/runtime-parameters?view=azure-devops&tabs=script) can meet your needs? Some details about how to use it see my [another issue](https://stackoverflow.com/a/60983879/10910450). – LoLance May 08 '20 at 01:09
  • 2
    again the OP is in regards to Release Pipelines, there is no love from MS over there as they are not YAML yet. – Jeff Patton May 08 '20 at 16:57
  • Most developers want to pass the selected value of the drop down list as a variable to the pipeline. This should be neat and easy feature to add. I would also like to have more features added, similar to Octopus Deploy - such as scoping variables to environments. – Tore Aurstad Sep 13 '20 at 18:57
3

UPDATE: at least 4 values needed

Dropdown appears automatically in Run Pipeline window when you pre-defined at least a certain number of values.

For example, see the following parameter definition with 9 pre-defined values. However, I do not know what the minimum number of values is to display a dropdown.

parameters:
  - name: DATABASE_TIER
    displayName: Tenant Database Tier
    type: string
    default: S0
    values:
      - S0
      - S1
      - S2
      - S3
      - S4
      - S6
      - S7
      - S9
      - S12

enter image description here