slikts
slikts

Reputation: 8158

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

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 }}

Upvotes: 1

Views: 1867

Answers (2)

Leo Liu
Leo Liu

Reputation: 76910

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

Upvotes: 0

Ked Mardemootoo
Ked Mardemootoo

Reputation: 1605

Would this work for you?

step:
- bash: |
    if [ ${{parameters.runstep}} ]; then
       ${{parameters.runstep}}
    fi

Upvotes: 1

Related Questions