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

     1  doc_meta: |
     2    folder: loop
     3    title: use dynamic variable in until
     4    head: |
     5      This shows how to use a dynamic variable to end the loop, which uses a changing variable in block func, callee task
     6  
     7    sections:
     8      - title: Demo
     9        log: yes
    10  
    11  tasks:
    12    -
    13      name: task
    14      task:
    15  
    16        -
    17          func: block
    18          desc: |
    19            break loop using until condition
    20          do:
    21            -
    22              func: cmd
    23              do:
    24                - name: print
    25                  cmd: '{{.loopitem}}'
    26  
    27          loop:
    28            - item1
    29            - item2
    30            - item3
    31            - item4
    32            - item5
    33            - item6
    34          until: '{{eq .loopitem "item4"}}'
    35  
    36        -
    37          func: cmd
    38          do:
    39            - name: print
    40              cmd: '----------------------------------------------------'
    41  
    42        -
    43          func: block
    44          desc: |
    45            in this case the until condition will use a var which is chaning in block func
    46            in order to make the interal var accessible by parent block func, you will have to use return cmd to return the value, otherwise the block func can not use right changing value in the condition
    47            also the_internal_var has be be defined somewhere: scope/global/local, otherwise it will result in a golang templating error
    48          dvars:
    49              - name: the_internal_var
    50                value: 'None'
    51          do:
    52            -
    53              func: cmd
    54              dvars:
    55                - name: the_internal_var
    56                  value: '{{.loopitem}}'
    57                  flags:
    58                    - taskScope
    59              do:
    60                - name: print
    61                  cmd: '{{.loopitem}}'
    62  
    63                - name: return
    64                  cmd:
    65                    - the_internal_var
    66            -
    67              func: cmd
    68              do:
    69                - name: print
    70                  cmd: 'post process {{.the_internal_var}} to see if this is executed'
    71  
    72          loop:
    73            - item1
    74            - item2
    75            - item3
    76            - item4
    77            - item5
    78            - item6
    79          until: '{{eq .the_internal_var "item4"}}'
    80  
    81        -
    82          func: cmd
    83          do:
    84            - name: print
    85              cmd: '----------------------------------------------------'
    86  
    87        -
    88          func: call
    89          vars:
    90            the_internal_var2: 'None'
    91          do: sub_task
    92          loop:
    93            - item1
    94            - item2
    95            - item3
    96            - item4
    97            - item5
    98            - item6
    99          until: '{{eq .the_internal_var2 "item4"}}'
   100  
   101  
   102        -
   103          func: cmd
   104          do:
   105            - name: inspect
   106              cmd:
   107                - exec_vars
   108  
   109    -
   110      name: sub_task
   111      task:
   112        -
   113          func: cmd
   114          dvars:
   115            - name: the_internal_var2
   116              value: '{{.loopitem}}'
   117          do:
   118            - name: print
   119              cmd: '{{.loopitem}}'
   120  
   121            - name: return
   122              cmd:
   123                - the_internal_var2
   124