condition with until
This showcases using until key word to exit loop
Demo
source
Main task yaml file
goal:
- introduce until key word to exit loop
- deom 3 loop cases
tasks:
- name: task
desc: main entry
task:
- func: cmd
name: step1
desc: demo it will loop until loopitem = item3
do:
- name: print
cmd: '{{.loopitem}}'
loop:
- item1
- item2
- item3
- item4
until: '{{ eq .loopitem "item3" }}'
- func: cmd
name: step2
do:
- name: print
cmd: hello
- func: call
name: step3
do: subtask
loop:
- proc 1
- proc 2
- proc 3
- proc 4
until: '{{ eq .loopitem "proc 3" }}'
- func: call
name: step4
do: subtask
loop:
- proc 1
- proc 2
- proc 3
- proc 4
until: '{{ eq .loopindex 3 }}'
- func: call
name: step5
desc: it will stop loop at proc 4
vars:
person: jason
do: subtask2
loop:
- proc 1
- proc 2
- proc 3
- proc 4
- proc 5
- proc 6
until: '{{ eq .person "tom" }}'
- name: subtask
desc: subtask to test reg and return
task:
- func: cmd
name: step1
desc: the loopitem here is inherited from caller
do:
- name: print
cmd: '{{.loopitem}}'
- name: subtask2
task:
- func: cmd
do:
- name: reg
cmd:
name: person
value: tom
if: '{{ eq .loopindex 3 }}'
- func: cmd
name: step2
do:
- name: print
cmd: 'person: {{.person}}'
Main log file
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0119
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/c0119
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: main entry ]
-Step1: [step1: demo it will loop until loopitem = item3 ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
item1
~SubStep1: [print: ]
item2
-Step2: [step2: ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
hello
-Step3: [step3: ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
=Task2: [task ==> subtask: subtask to test reg and return ]
--Step1: [step1: the loopitem here is inherited from caller ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"loopitem": "proc 1",
"loopindex": 0,
"loopindex1": 1
})
~~SubStep1: [print: ]
proc 1
=Task2: [task ==> subtask: subtask to test reg and return ]
--Step1: [step1: the loopitem here is inherited from caller ]
self: final context exec vars:
(*core.Cache)({
"loopindex": 1,
"loopindex1": 2,
"up_runtime_task_layer_number": 1,
"loopitem": "proc 2"
})
~~SubStep1: [print: ]
proc 2
-Step4: [step4: ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1
})
=Task2: [task ==> subtask: subtask to test reg and return ]
--Step1: [step1: the loopitem here is inherited from caller ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"loopitem": "proc 1",
"loopindex": 0,
"loopindex1": 1
})
~~SubStep1: [print: ]
proc 1
=Task2: [task ==> subtask: subtask to test reg and return ]
--Step1: [step1: the loopitem here is inherited from caller ]
self: final context exec vars:
(*core.Cache)({
"loopitem": "proc 2",
"loopindex": 1,
"loopindex1": 2,
"up_runtime_task_layer_number": 1
})
~~SubStep1: [print: ]
proc 2
=Task2: [task ==> subtask: subtask to test reg and return ]
--Step1: [step1: the loopitem here is inherited from caller ]
self: final context exec vars:
(*core.Cache)({
"loopitem": "proc 3",
"loopindex": 2,
"loopindex1": 3,
"up_runtime_task_layer_number": 1
})
~~SubStep1: [print: ]
proc 3
-Step5: [step5: it will stop loop at proc 4 ]
self: final context exec vars:
(*core.Cache)({
"person": "jason",
"up_runtime_task_layer_number": 1
})
=Task3: [task ==> subtask2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"person": "jason",
"loopitem": "proc 1",
"loopindex": 0,
"loopindex1": 1,
"up_runtime_task_layer_number": 1
})
condition failed, skip executing step
--Step2: [step2: ]
self: final context exec vars:
(*core.Cache)({
"loopindex": 0,
"loopindex1": 1,
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 1"
})
~~SubStep1: [print: ]
person: jason
=Task3: [task ==> subtask2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 2",
"loopindex": 1,
"loopindex1": 2
})
condition failed, skip executing step
--Step2: [step2: ]
self: final context exec vars:
(*core.Cache)({
"loopindex": 1,
"loopindex1": 2,
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 2"
})
~~SubStep1: [print: ]
person: jason
=Task3: [task ==> subtask2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 3",
"loopindex": 2,
"loopindex1": 3
})
condition failed, skip executing step
--Step2: [step2: ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 3",
"loopindex": 2,
"loopindex1": 3
})
~~SubStep1: [print: ]
person: jason
=Task3: [task ==> subtask2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"person": "jason",
"loopitem": "proc 4",
"loopindex": 3,
"loopindex1": 4
})
~~SubStep1: [reg: ]
--Step2: [step2: ]
self: final context exec vars:
(*core.Cache)({
"loopindex1": 4,
"up_runtime_task_layer_number": 1,
"person": "tom",
"loopitem": "proc 4",
"loopindex": 3
})
~~SubStep1: [print: ]
person: tom
Logs with different verbose level
Raw logs with different verbose level