Azure Devops Pipeline: Second parameter dependent on the first parameter

Viewed 2033

Is it possible in azure devops that the choice of the first parameter by the user, determines the second parameter (type, displayName etc.)?

For example:

parameters:
- name: parametr1
  displayName: example1
  type: string
  default: first
  values:
  - first
  - second
  - third

And if the user selects "first" when starting the pipeline, the second parameter to enter:

- name: parametr2.1
  displayName: example2
  type: number

But if the user selects "second" when starting the pipeline, the second parameter to enter:

- name: parametr2.2
      displayName: example2.2
      type: boolean

   

Thanks for any help :)

1 Answers

Azure Devops Pipeline: Second parameter dependent on the first parameter

I am afraid there is no such out of way to resolve this question at this moment.

That because the conditions does not support for parameters at present. We could not add condition to the second parameter to set the value based on the first parameter.

As we know, the Runtime parameters is used to let you have more control over what values can be passed to a pipeline.

Since the second parameter is depend on the first parameter, does not require us to manually control it.

So, as workaround for this question, we could use the Logging Command with condition to set the second parameter based on the value of first parameter:

parameters:
- name: parametr1
  displayName: example1
  type: string
  default: first
  values:
  - first
  - second
  - third

trigger: none

jobs:
- job: build
  displayName: build
  pool: 
    name: MyPrivateAgent

  steps:
  - task: InlinePowershell@1
    displayName: 'SetVariableV1'
    inputs:
      Script: 'Write-Host "##vso[task.setvariable variable=parametr2.1;]123456"'
    condition: and(succeeded(), eq('${{ parameters.parametr1 }}', 'first'))

  - task: InlinePowershell@1
    displayName: 'SetVariableV2'
    inputs:
      Script: 'Write-Host "##vso[task.setvariable variable=parametr2.2;]true"'
    condition: and(succeeded(), eq('${{ parameters.parametr1 }}', 'second'))

I test it on my side, it works fine.

Related