local vs reg global
Showcase that local var is only available in local runtime for that func, if you need to use it global runtime, you will need to use template func reg or reg cmd to set it in global runtime
Prerequisites
- template reg action
- reg cmd
references
Demo
source
Main task yaml file
tasks:
- name: task
desc: test the exit scenarios due to different types of validation
task:
- func: shell
desc: step1
do:
- echo hanks
- func: cmd
desc: |
test register a variable to global vars
the reg_hello should be <no value> since this is a template action
you should really use dvar name void instead
dvars:
- name: reg_hello
value: |
{{.last_result.Output |reg "hellomsg" }}
- func: shell
do:
- echo "{{.reg_hello}}"
- echo "{{.hellomsg}}"
- func: cmd
desc: |
the reg_tom's value is a object, but since reg_tom is only a local, it
will probably not very useful
vars:
person:
name: tom
age: 18
dvars:
- name: local_tom
value: |-
my name is tom
{{.person |reg "tom" }}
flags: [vvv]
do:
- name: reg
cmd:
name: global_tom
value: '{{.local_tom}}'
- func: cmd
desc: debug the results
vars:
objname: global_tom
do:
- name: print
desc: this local_tom should be <no value> as it is in scope of last step
cmd: "{{.local_tom}}"
- name: print
desc: get the object from register global space
cmd: "{{.tom}}"
- name: printObj
desc: "dynamically reference to global_tom object registered"
cmd: "{{.objname}}"
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 -> c0076
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/c0076
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: test the exit scenarios due to different types of validation ]
-Step1: [: step1 ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
cmd( 1):
echo hanks
-
hanks
-
.. ok
. ok
-Step2: [
test register a variable to global vars
the reg_hello should be <no value> since this is a template action
you should really use dvar name void instead
]
self: final context exec vars:
(*core.Cache)({
"reg_hello": "hanks\n\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo hanks",
Code: 0,
Output: "hanks",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"hellomsg": "hanks"
})
WARN: [cmd] - [Not implemented or void for no action!]
-Step3:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"last_result": (*utils.ExecResult)({
Cmd: "echo hanks",
Code: 0,
Output: "hanks",
ErrMsg: ""
}),
"hellomsg": "hanks"
})
cmd( 1):
echo "{{.reg_hello}}"
-
<no value>
-
.. ok
cmd( 2):
echo "{{.hellomsg}}"
-
hanks
-
.. ok
. ok
-Step4: [
the reg_tom's value is a object, but since reg_tom is only a local, it
will probably not very useful
]
dvar> local_tom:
"my name is tom\nage: 18\nname: tom\n"
-
my name is tom
age: 18
name: tom
self: final context exec vars:
(*core.Cache)({
"last_result": (*utils.ExecResult)({
Cmd: "echo \"hanks\"",
Code: 0,
Output: "hanks",
ErrMsg: ""
}),
"hellomsg": "hanks",
"up_runtime_task_layer_number": 0,
"person": {
"name": "tom",
"age": 18
},
"tom": {
"name": "tom",
"age": 18
},
"local_tom": "my name is tom\nage: 18\nname: tom\n"
})
~SubStep1: [reg: ]
-Step5: [: debug the results ]
self: final context exec vars:
(*core.Cache)({
"global_tom": "my name is tom\nage: 18\nname: tom\n",
"up_runtime_task_layer_number": 0,
"objname": "global_tom",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"hanks\"",
Code: 0,
Output: "hanks",
ErrMsg: ""
}),
"hellomsg": "hanks",
"tom": {
"name": "tom",
"age": 18
}
})
~SubStep1: [print: this local_tom should be <no value> as it is in scope of last step ]
None
~SubStep2: [print: get the object from register global space ]
map[age:18 name:tom]
~SubStep3: [printObj: dynamically reference to global_tom object registered ]
object:
global_tom: "my name is tom\nage: 18\nname: tom\n"
Logs with different verbose level
Raw logs with different verbose level
Other references: