示範在 for 迴圈內建立的變數的本機範圍

說明在迴圈中建立的任何變數不會出現在該迴圈之外。

深入探索

如需包含此程式碼範例的詳細說明文件,請參閱以下文件:

程式碼範例

YAML

- init:
    assign:
      - workflowScope: foo
- outerLoop:
    for:
      value: outerLoopValue  # outerLoopValue does not exist outside of outerLoop step
      in: [1, 2, 3, 4]
      steps:
        - outerLoopAssign:
            assign:
              - outerLoopScope: ${workflowScope}  # outerLoopScope is a new variable and does not exist outside of outerLoop step
        - innerLoop:
            for:
              value: innerLoopValue  # innerLoopValue does not exist outside of innerLoop step
              in: [5, 6, 7, 8]
              steps:
                - innerLoopAssign:
                    assign:
                      - workflowScope: ${innerLoopValue}
                      - innerLoopScope: ${outerLoopScope}  # innerLoopScope is a new variable and does not exist outside of innerLoop step
- final:
    return:
      - ${workflowScope}  # allowed
      # - ${outerLoopScope}  # not allowed
      # - ${innerLoopScope}  # not allowed
      # - ${outerLoopValue}  # not allowed

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱 Google Cloud 範例瀏覽器