The OneCloud iterator function is a powerful capability to leverage a static list or list output and set a temporary variable based upon the current value in a list. If you are new to lists, imagine asking the owner of a fruit stand what type of fruits are available. The response might say “we have apples, oranges, and bananas”. This is an example of a list and with 3 elements for each type of fruit. Let’s apply this concept to OneCloud whereby we want to run the command as many times as there are types of fruit. If we are using the example above, the command would execute 3 times for each value in the list. Here is an example of creating three separate directories for each fruit:
- Select the Build on the side navigation.
- Select the DEV environment.
- Add a new Chain and name it "Iterator Example".
- Add a Command File Utilities -> Create Directory by dragging on to the pallet.
(Hint: use the Find tool to search for "File Utilities" and then search for "Create Directory")
- Slide on the iterator option.
- Type in the three elements for each fruit - "apples", "oranges", and "bananas".
(Hint: Press <ENTER> after each fruit is added)
- In the Directory parameter, type in the value "/tmp/" and select the Command iterator temporary variable from the variable selector.
- Save the command.
- Publish and run the chain.
Sourcing Lists from Output
In the example above, the list was fixed in the command, however, it is most common to source lists from a command output so they are dynamic such as a list of files.