environment vars
This showcases:
- How to use env variables and provide a default value if it is empty
- An minimal entry task could be just a name
- The empty value is mapped to None value internnally
Demo
source
Main task yaml file
scopes:
- name: global
dvars:
- name: student_name
value: '{{ env "STUDENT_NAME" |default "Tom Hanks" }}'
- name: student_age
value: '{{ env "STUDENT_AGE" |default 28 }}'
dvars:
- name: cli
value: |
echo """
student details:
name: {{.student_name}}
age: {{.student_age}}
"""
tasks:
- name: task
task:
- func: shell
desc: this show an example of the empty value is mapped to None
vars:
person: ""
dvars:
- name: someone
value: '{{ .person }}'
- name: i_am_empty
value: '{{ "" }}'
- name: empty_env_var
value: '{{ env "EMPTY_VAR" }}'
do: |
echo "{{.someone}}"
echo "{{.i_am_empty}}"
echo "{{.empty_env_var}}"
- func: cmd
do:
- name: inspect
cmd:
- exec_vars
- exec_base_vars
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 -> c0046
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/c0046
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1: [: this show an example of the empty value is mapped to None ]
self: final context exec vars:
(*core.Cache)({
"someone": "None",
"student_name": "Tom Hanks",
"student_age": "28",
"cli": "echo \"\"\"\nstudent details:\nname: Tom Hanks\nage: 28\n\"\"\"\n",
"up_runtime_task_layer_number": 0,
"person": "",
"i_am_empty": "None",
"empty_env_var": "None"
})
cmd( 1):
echo "{{.someone}}"
echo "{{.i_am_empty}}"
echo "{{.empty_env_var}}"
-
None
None
None
-
.. ok
. ok
-Step2:
self: final context exec vars:
(*core.Cache)({
"student_name": "Tom Hanks",
"student_age": "28",
"cli": "echo \"\"\"\nstudent details:\nname: Tom Hanks\nage: 28\n\"\"\"\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"None\"\necho \"None\"\necho \"None\"\n",
Code: 0,
Output: "None\nNone\nNone",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0
})
~SubStep1: [inspect: ]
1: inspect[exec_vars]
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"student_name": "Tom Hanks",
"student_age": "28",
"cli": "echo \"\"\"\nstudent details:\nname: Tom Hanks\nage: 28\n\"\"\"\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"None\"\necho \"None\"\necho \"None\"\n",
Code: 0,
Output: "None\nNone\nNone",
ErrMsg: ""
})
})
2: inspect[exec_base_vars]
{
"student_name": "Tom Hanks",
"student_age": "28",
"cli": "echo \"\"\"\nstudent details:\nname: Tom Hanks\nage: 28\n\"\"\"\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"None\"\necho \"None\"\necho \"None\"\n",
Code: 0,
Output: "None\nNone\nNone",
ErrMsg: ""
})
}
Logs with different verbose level
Raw logs with different verbose level