github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0026.yml (about)

     1  doc_meta: |
     2    folder: shell-func
     3    title: register result
     4    head: |
     5      Showcase you can use reg in shell func to register the result to global runtime
     6  
     7    sections:
     8      - title: Rules
     9        content: |
    10          * if reg=auto, it will use naming pattern: taskname_stepname_result, if stepname is empty, then it will use the index of the step instead, eg: taskname_0_result
    11          * otherwise use the defined name as var name
    12  
    13      - title: Demo
    14        log: yes
    15  
    16  notes:
    17    goal:
    18      - to test register a var/dvar into vars
    19      - once registered, the later step can consume the registered vars
    20  
    21    design:
    22      - if reg=auto, use the register_taskname_stepname as var name
    23      - otherwise use the defined name as var name
    24  
    25  tasks:
    26    -
    27      name: task
    28      task:
    29        -
    30          func: call
    31          do:
    32            - test1
    33            - test2
    34            - test3
    35  
    36    -
    37      name: test1
    38      desc: |
    39        test reg with an auto registered name
    40        in this case the step name is empty, then the idx will be used
    41      task:
    42        -
    43          func: shell
    44          desc: if this step does not have a name, then the auto reg name would be task_0_reslt
    45          do:
    46            - 'curl -s -X GET "https://httpbin.org/get" -H "accept: application/json"'
    47          reg: auto
    48  
    49        - func: cmd
    50          do:
    51            - name: print
    52              cmd: '{{.test1_0_result.Code}}'
    53            - name: print
    54              cmd: '{{.test1_0_result.Output}}'
    55  
    56    -
    57      name: test2
    58      desc: |
    59        test reg with a auto registered name and the step name is not empty
    60        in this case the registered reslt name is: test2_httpbinget_result
    61      task:
    62        -
    63          func: shell
    64          name: httpbinget
    65          desc: if this step does not have a name, then the auto reg name would be task_0_reslt
    66          do:
    67            - 'curl -s -X GET "https://httpbin.org/get" -H "accept: application/json"'
    68          reg: auto
    69  
    70        - func: cmd
    71          do:
    72            - name: print
    73              cmd: '{{.test2_httpbinget_result.Code}}'
    74            - name: print
    75              cmd: '{{.test2_httpbinget_result.Output}}'
    76  
    77    -
    78      name: test3
    79      desc: |
    80        test reg with a registered name
    81        in this case the registered reslt name is: test2_httpbinget_result
    82      task:
    83        -
    84          func: shell
    85          name: httpbinget
    86          desc: it will use the given name as var name to register the result
    87          do:
    88            - 'curl -s -X GET "https://httpbin.org/get" -H "accept: application/json"'
    89          reg: httpbin_get_result
    90  
    91        - func: cmd
    92          do:
    93            - name: print
    94              cmd: '{{.httpbin_get_result.Code}}'
    95            - name: print
    96              cmd: '{{.httpbin_get_result.Output}}'