If a reference to a variable or sub elment does not exist, it will be false by default
vars:
student:
name: tom
sex: male
tasks:
- name: task
desc: main entry
task:
- func: cmd
do:
- name: print
cmd: '{{.student.name}}'
- name: print
cmd: '{{.student.age}}'
# - name: print
# cmd: '{{.student.age | len}}'
- func: cmd
do:
- name: print
cmd: hello tom
if: '{{eq .student.name "tom"}}'
- func: cmd
desc: add support if the element does not exist, then if condition should be false
by default
dvars:
- name: student_age
value: '.student.age'
do:
- name: assert
desc: |
this cmd will not evaluated as it will not reach here
the below evaluate will cause issue, as age does not exist
always map to a dvar first
cmd: '{{eq .student.age "None"}}'
- name: print
cmd: '{{.student.age}}'
- name: print
cmd: |
you will not see this message
if: '{{eq .student_age "None"}}'
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0122
Verbose -> vvv
ModuleName -> self
ShellType -> /bin/sh
MaxCallLayers -> 8
Timeout -> 3600000
MaxModuelCallLayers -> 256
EntryTask -> task
ModRepoUsernameRef ->
ModRepoPasswordRef ->
work dir: /up_project/up
-exec task: task
loading [Task]: ./tests/functests/c0122
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: main entry ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"student": {
"sex": "male",
"name": "tom"
}
})
~SubStep1: [print: ]
tom
~SubStep2: [print: ]
None
-Step2:
self: final context exec vars:
(*core.Cache)({
"student": {
"name": "tom",
"sex": "male"
},
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
hello tom
-Step3: [: add support if the element does not exist, then if condition should be false by default ]
self: final context exec vars:
(*core.Cache)({
"student": {
"name": "tom",
"sex": "male"
},
"up_runtime_task_layer_number": 0,
"student_age": ".student.age"
})
condition failed, skip executing step