vars in func

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

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

Glabal vars

The global vasrs are the one defined externally to the tasks definition, eg:

vars:
  a: runtime-a
  e: runtime-e
  k: runtime-k
  studentname: Jason

Local vars

The local vasrs are the one defined within the func definition, eg:

vars:
  studentname: Tom
  school: SG

Auto merge

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

Demo

source

Main task yaml file
    vars:
      a: runtime-a
      e: runtime-e
      k: runtime-k
      studentname: Jason
    tasks:
    - name: task
      task:
      - func: shell
        name: step1
        desc: to test display env vars from shell context
        vars:
          studentname: Tom
          school: SG
        do:
        - echo "hello, world"
        - echo "hello {{.studentname}}"
    
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 -> c0013
                 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/c0013
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [step1: to test display env vars from shell context ]
    self: final context exec vars:
    
    (*core.Cache)({
      "school": "SG",
      "a": "runtime-a",
      "e": "runtime-e",
      "k": "runtime-k",
      "studentname": "Tom",
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "hello, world"
    
    -
    hello, world
    
    -
     .. ok
    cmd( 2):
    echo "hello {{.studentname}}"
    
    -
    hello Tom
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level

What to observe in log file

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

-------runtime global final merged with dvars-------

{
  "k": "runtime-k",
  "studentname": "Jason",
  "a": "runtime-a",
  "e": "runtime-e"
}

overall final exec vars:

{
  "a": "runtime-a",
  "e": "runtime-e",
  "school": "SG",
  "k": "runtime-k",
  "studentname": "Tom"
}