I am trying to update an existing template to have a new step that is skipped if a parameter passed in is not there or is false.
I would like the template to work in both these scenarios:
---
kind: template
load: test_template.yaml
data:
do_thing: false
and:
---
kind: template
load: test_template.yaml
My template currently looks something like this (I have stripped out all the other steps for sake of ease):
---
kind: pipeline
type: docker
name: test_pipeline
trigger:
event:
- push
steps:
- name: skippable-step
image: <SOME BUILD AGENT>
pull: always
commands:
- echo passed in value - {{ .input.do_thing }}
- |
if [[ ! -z "{{ .input.do_thing }}" ]] && [[ "{{ .input.do_thing }}" == "true" || "{{ .input.do_thing }}" == "1" || "{{ .input.do_thing }}" == "TRUE" ]] ; then
echo "It did a thing"
fi
The step is essentially just trying to check if the value is there and if it’s true it executes.
Currently the step fails with the following logs:
+ echo passed in value - <no value>
/bin/sh: line 39: syntax error near unexpected token `newline'
Are there any ways to have optional parameters?
Can we set them to default values when not passed in?
How can I roll out an optional step without breaking existing users of the pipeline if optional parameters are not allowed?