0

When using a template parameter like this:

parameters:
- name: runStep
  type: step

It always requires passing a value. I would, however, like to make it optional:

parameters:
- name: runStep
  type: step
  default: ???

For stepList it can be done like so:

- name: runSteps
  type: stepList
  default: []

But how could it be done for type step? I could add a "dummy" default value:

default:
  script: echo 123

However, how could I compare that value in a condition? I'd like to do something like this:

- ${{ if parameters.runStep }}:
  - ${{ parameters.runStep }}
slikts
  • 8,020
  • 1
  • 27
  • 47

2 Answers2

1

Would this work for you?

step:
- bash: |
    if [ ${{parameters.runstep}} ]; then
       ${{parameters.runstep}}
    fi
Ked Mardemootoo
  • 1,480
  • 1
  • 5
  • 19
0

What should a YAML template optional step parameter default value be?

According to the document Template types & usage:

enter image description here

So, the default value of YAML template optional step parameter should be a step, like:

parameters:
- name: myStep
  type: step
  default:
    script: echo my step

steps:
- ${{ if parameters.runStep }}:
  - ${{ parameters.runStep }}
  - script: echo HelloWorld!

enter image description here

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    This would always execute because the default value would always be a step, so the condition (`if parameters.runStep`) is pointless. – slikts Jun 03 '21 at 15:19