github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0013.yml (about) 1 doc_meta: | 2 folder: vars 3 title: vars in func 4 head: | 5 The vars definition block in a func(shell in this case) make the vars' scope to be local scope to the func, the var defined in the local scope is only available in all the execution steps in that func 6 7 It is similar to func or method in most of programming languages, the vars defined in local scope in func are only avaiable in local scope callee task is reprented using a var name make it dynamic in execution time 8 9 sections: 10 - title: Glabal vars 11 content: | 12 The global vasrs are the one defined externally to the tasks definition, eg: 13 ``` 14 vars: 15 a: runtime-a 16 e: runtime-e 17 k: runtime-k 18 studentname: Jason 19 ``` 20 21 - title: Local vars 22 content: | 23 The local vasrs are the one defined within the func definition, eg: 24 ``` 25 vars: 26 studentname: Tom 27 school: SG 28 ``` 29 30 - title: Auto merge 31 content: | 32 During the runtime of step1, it will merge the vars with the same name, the local vars take priority. In this demo, the var studentname will be Tom instead of Jason 33 34 35 - title: Demo 36 log: yes 37 38 - title: What to observe in log file 39 content: | 40 do check the verbosed log in vvv level, you will see that studentname exist only in local var scope, which are the final exec vars 41 ``` 42 -------runtime global final merged with dvars------- 43 44 { 45 "k": "runtime-k", 46 "studentname": "Jason", 47 "a": "runtime-a", 48 "e": "runtime-e" 49 } 50 51 overall final exec vars: 52 53 { 54 "a": "runtime-a", 55 "e": "runtime-e", 56 "school": "SG", 57 "k": "runtime-k", 58 "studentname": "Tom" 59 } 60 61 ``` 62 63 notes: 64 goal: 65 - to test vars without scope will still work 66 67 vars: 68 a: runtime-a 69 e: runtime-e 70 k: runtime-k 71 studentname: Jason 72 73 tasks: 74 75 - 76 name: task 77 task: 78 - 79 func: shell 80 name: step1 81 desc: to test display env vars from shell context 82 vars: 83 studentname: Tom 84 school: SG 85 do: 86 - echo "hello, world" 87 - echo "hello {{.studentname}}"