github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0046.yml (about) 1 doc_meta: | 2 folder: env-vars 3 title: environment vars 4 head: | 5 This showcases: 6 * How to use env variables and provide a default value if it is empty 7 * An minimal entry task could be just a name 8 * The empty value is mapped to None value internnally 9 10 sections: 11 - title: Demo 12 log: yes 13 14 notes: 15 goal: 16 - showcase the bare minimal entry point is just a named task only 17 - showcase how to gracefully manage the env vars 18 19 storys: 20 - a cli script requires 2 input from env vars 21 - | 22 it also requires 2 config vars in a profile 23 based config for different execution context/env, 24 eg dev/st/prod 25 - it should take the env var from current bash/shell environment 26 - the env vars: 27 student_name: | 28 if it can not find it, it fails fast and execution stops 29 ref to f0045 for the failed case 30 student_age: if it can not find it, defaul it to 18 31 32 scopes: 33 34 - name: global 35 dvars: 36 - name: student_name 37 value: '{{ env "STUDENT_NAME" |default "Tom Hanks" }}' 38 - name: student_age 39 value: '{{ env "STUDENT_AGE" |default 28 }}' 40 41 dvars: 42 - name: cli 43 value: | 44 echo """ 45 student details: 46 name: {{.student_name}} 47 age: {{.student_age}} 48 """ 49 50 tasks: 51 52 - 53 name: task 54 task: 55 - 56 func: shell 57 desc: this show an example of the empty value is mapped to None 58 vars: 59 person: "" 60 dvars: 61 - name: someone 62 value: '{{ .person }}' 63 64 - name: i_am_empty 65 value: '{{ "" }}' 66 67 - name: empty_env_var 68 value: '{{ env "EMPTY_VAR" }}' 69 do: | 70 echo "{{.someone}}" 71 echo "{{.i_am_empty}}" 72 echo "{{.empty_env_var}}" 73 74 - 75 func: cmd 76 do: 77 - 78 name: inspect 79 cmd: 80 - exec_vars 81 - exec_base_vars