else with a flow
Showcase that you could use a flow of a serial of steps in else branch。 In this case, you don not have to route the logic to a external task
Demo
source
Main task yaml file
vars:
goahead: False
# goahead: True
tasks:
- name: task
task:
- func: cmd
do:
- name: print
cmd: |
true/false value of goahead:
{{.goahead}}
{{not .goahead}}
- func: call
desc: show use a flow in else
do:
- goahead
if: '{{.goahead}}'
else:
- func: cmd
do:
- name: print
cmd: 'do something else step1 .......'
- func: shell
do:
- echo do something else step2 .......
- func: cmd
do:
- name: print
cmd: 'do something else step3 .......'
- func: call
desc: show it is same that you could assemble a list of tasks for if true condition
vars:
goahead: True
do:
- goelse
- name: goahead
task:
- func: cmd
do:
- name: print
cmd: 'go ahead .......'
- name: goelse
task:
- func: cmd
do:
- name: print
cmd: 'do something else .......'
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 -> c0131
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/c0131
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"goahead": false,
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
true/false value of goahead:
false
true
-Step2: [: show use a flow in else ]
self: final context exec vars:
(*core.Cache)({
"goahead": false,
"up_runtime_task_layer_number": 0
})
-Step1:
self: final context exec vars:
(*core.Cache)({
"goahead": false,
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
do something else step1 .......
-Step2:
self: final context exec vars:
(*core.Cache)({
"goahead": false,
"up_runtime_task_layer_number": 0
})
cmd( 1):
echo do something else step2 .......
-
do something else step2 .......
-
.. ok
. ok
-Step3:
self: final context exec vars:
(*core.Cache)({
"goahead": false,
"last_result": (*utils.ExecResult)({
Cmd: "echo do something else step2 .......",
Code: 0,
Output: "do something else step2 .......",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
do something else step3 .......
-Step4: [: show it is same that you could assemble a list of tasks for if true condition ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"goahead": true,
"last_result": (*utils.ExecResult)({
Cmd: "echo do something else step2 .......",
Code: 0,
Output: "do something else step2 .......",
ErrMsg: ""
})
})
=Task3: [task ==> goelse: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"goahead": true,
"last_result": (*utils.ExecResult)({
Cmd: "echo do something else step2 .......",
Code: 0,
Output: "do something else step2 .......",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 1
})
~~SubStep1: [print: ]
do something else .......
Logs with different verbose level
Raw logs with different verbose level