task scope
So far, we have scoped vars and eventually they will be living in global runtime or local scope in a func, when you need to access the var across funcs, then you will have to define it in global runtime vars, or grouped vars scope, or register a var to glbale runtime. In this demo, we show that you can use taskScope flag to mark a dvar to be in task scope, so that you can easily access this task scope var accross different funcs
Demo
source
Main task yaml file
vars:
tom: this is tom
tasks:
- name: task
task:
- func: cmd
vars:
jerry: this is jerry
do:
- name: print
cmd: '{{.tom}}'
- name: print
cmd: '{{.jerry}}'
- func: cmd
do:
- name: print
desc: jerry is in local scope so there is no value
cmd: '{{.jerry}}'
- func: cmd
dvars:
- name: jerry
value: this is jerry in task scope
flags:
- taskScope
do:
- name: print
desc: this should print out the dvar value of jerry
cmd: '{{.jerry}}'
- func: cmd
do:
- name: print
desc: this should print out the dvar value of jerry as it is declared jerry
is in taskScope
cmd: '{{.jerry}}'
- func: cmd
vars:
jerry: jerry is overrided in local scope
do:
- name: print
desc: var jerry in task scope is overrided by local var jerry
cmd: '{{.jerry}}'
- func: cmd
do:
- name: print
desc: this should print out the jerry defined in task var scope
cmd: '{{.jerry}}'
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 -> c0108
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/c0108
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"tom": "this is tom",
"up_runtime_task_layer_number": 0,
"jerry": "this is jerry"
})
~SubStep1: [print: ]
this is tom
~SubStep2: [print: ]
this is jerry
-Step2:
self: final context exec vars:
(*core.Cache)({
"tom": "this is tom",
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: jerry is in local scope so there is no value ]
None
-Step3:
self: final context exec vars:
(*core.Cache)({
"jerry": "this is jerry in task scope",
"tom": "this is tom",
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: this should print out the dvar value of jerry ]
this is jerry in task scope
-Step4:
self: final context exec vars:
(*core.Cache)({
"jerry": "this is jerry in task scope",
"tom": "this is tom",
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: this should print out the dvar value of jerry as it is declared jerry is in taskScope ]
this is jerry in task scope
-Step5:
self: final context exec vars:
(*core.Cache)({
"tom": "this is tom",
"up_runtime_task_layer_number": 0,
"jerry": "jerry is overrided in local scope"
})
~SubStep1: [print: var jerry in task scope is overrided by local var jerry ]
jerry is overrided in local scope
-Step6:
self: final context exec vars:
(*core.Cache)({
"jerry": "this is jerry in task scope",
"tom": "this is tom",
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: this should print out the jerry defined in task var scope ]
this is jerry in task scope
Logs with different verbose level
Raw logs with different verbose level