vars intro

Scope is concept of named context encapsulation. For example, for a software development, you will probably have development env, namely dev; system test env, namely st; staging env etc, all group to a non-prod group. Then prod env and disaster recovery env, grouped into prod group

Also you could have a global defined scope for common vars for all groups to inherit their vars to be the default from if not defined in that scope

So put it in simple example, if you have nonprod and prod group defined, then your runtime instance id (eg dev) belonging to a nonprod id will automatically inherit all vars definition from top to down, from vars defintion in global group, to nonprod group, then dev, then global runtime, during func execution runtime, they will merge with the local vars

How to run

run shell command: up ngo task -d ./tests/functests -t c0008.yml -i dev -v vvv –configdir=./tests/functests

Instance id

An execution of UP cli cmd can take an instance id for execution, in this demo, it is dev as example, if you do not use any instance id, by default, your execution will inherit from global group, then global runtime, then local vars

Demo

source

Main task yaml file
    scopes:
    - name: global
      vars:
        a: global-a
        b: global-b
        c: global-c
        d: global-d
    - name: prod
      members: [dr, prod]
      vars:
        a: prod-a
        c: prod-c
    - name: nonprod
      members:
      - dev
      - st
      - staging
      vars:
        a: non-prod-a
        b: non-prod-b
        c: non-prod-c
    - name: staging
      vars:
        a: staging-a
        b: staging-b
    - name: dev
      vars:
        a: dev-a
        c: dev-c
    tasks:
    - name: task
      task:
      - func: shell
        do:
        - echo "test out the var scopes only"
    
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 -> c0008
                 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/c0008
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "a": "dev-a",
      "b": "non-prod-b",
      "c": "dev-c",
      "d": "global-d",
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "test out the var scopes only"
    
    -
    test out the var scopes only
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level

Demo result

This demo will have an expected result of

overall final exec vars:

(*core.Cache)({
  "a": "dev-a",
  "b": "non-prod-b",
  "c": "dev-c",
  "d": "global-d"
})