var scope and accessibility
Showcase the var scope, how local var and global is diffent
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
cmd: '{{.jerry}}'
- name: reg
cmd:
name: hitom
desc: by default hitom is registered in to global context
value: 'hello, {{.tom}}'
- name: print
cmd: '{{.hitom}}'
- func: cmd
do:
- name: print
desc: by default hitom is accessible from global context, that's why it is accessiable
cross func
cmd: '{{.hitom}}'
- name: reg
cmd:
name: hijerry
desc: hijerry is registered to local scope only
value: 'hello, jerry'
flags: [localOnly]
- name: print
desc: expecting to see its value since it is still in same func scope
cmd: '{{.hijerry}}'
- func: cmd
do:
- name: print
desc: hijerry is not accessible here and got <no value>
cmd: '{{.hijerry}}'
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 -> c0105
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/c0105
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)({
"up_runtime_task_layer_number": 0,
"tom": "this is tom"
})
~SubStep1: [print: ]
None
~SubStep2: [reg: ]
~SubStep3: [print: ]
hello, this is tom
-Step3:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"tom": "this is tom",
"hitom": "hello, this is tom"
})
~SubStep1: [print: by default hitom is accessible from global context, that's why it is accessiable cross func ]
hello, this is tom
~SubStep2: [reg: ]
~SubStep3: [print: expecting to see its value since it is still in same func scope ]
hello, jerry
-Step4:
self: final context exec vars:
(*core.Cache)({
"hitom": "hello, this is tom",
"tom": "this is tom",
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: hijerry is not accessible here and got <no value> ]
None
Logs with different verbose level
Raw logs with different verbose level