Home > Net >  Azure yaml pipeline display parameter value and have another actual value
Azure yaml pipeline display parameter value and have another actual value

Time:09-21

I have a yaml pipeline in which I have a string parameter with several values. I want to have a human readable options to choose from but when reading the parameter I want to have an actual different value.

a psuedo yaml declaration for what I mean:

- name: actionParam
displayName: Choose Action
type: string
default: 'Action0': 'no action'
values:
- 'Action1' : 'drop tables'
- 'Action2' : 'hack NASA'
- 'Action3' : 'solve world hunger'

In this example I want for the user to see the options on the right but when doing {{parameters.actionParam}} I want to get the corresponding option on the left.

Is such a thing possible?

CodePudding user response:

Based on your requirement, you need to display parameter value and have another actual value.

I am afraid that there is no out-of-box method to achieve this requirement.

For a workaround, I suggest that you can define the parameters with the options on the right and then you can set the variable value based on the value of the parameters.

Here is an example:

parameters:
- name: actionParam
  displayName: Choose Action
  type: string
  default: 'no action'
  values:
  - 'drop tables'
  - 'hack NASA'
  - 'solve world hunger'

variables:
  - ${{ if eq(parameters.actionParam, 'solve world hunger') }}:
    - name: actionParam
      value: Action1
  - ${{ if eq(parameters.actionParam, 'drop tables') }}:
    - name: actionParam
      value: Action2  
  - ${{ if eq(parameters.actionParam, 'hack NASA') }}:
    - name: actionParam
      value: Action3

Result:

enter image description here

Then you can use the actual value with the format: $(actionParam)

  • Related