Skip to content

Commit

Permalink
docs: Add some title to examples
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Clucas <alan@clucas.org>
  • Loading branch information
Joibel committed Mar 10, 2023
1 parent ccb3a26 commit 68ae239
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/walk-through/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ There are two basic ways of running a template multiple times.
- a JSON object where each element in the object can be addressed by it's key as '{{item.key}}'
- `withParams` takes a JSON array of items, and iterates over it - again the items can be objects like with `withItems`. This is very powerful, as you can generate the JSON in another step in your workflow, so creating a dynamic workflow.

## `withItems` basic example
This example is the simplest. We are taking a basic list of items and iterating over it with `withItems`. It is limited to one varying field for each of the workflow templates instantiated.

```yaml
Expand Down Expand Up @@ -41,6 +42,7 @@ spec:
args: ["{{inputs.parameters.message}}"]
```
## `withItems` more complex example
If we'd like to pass more than one piece of information in each workflow, you can instead use a JSON object for each entry in `withItems` and then address the elements by key, as shown in this example.

```yaml
Expand Down Expand Up @@ -80,6 +82,7 @@ spec:
args: [/etc/os-release]
```

## `withParams` example
This example does exactly the same job as the previous example, but using `withParam` to pass the information as a JSON array argument, instead of hard-coding it into the template.

```yaml
Expand Down Expand Up @@ -128,6 +131,7 @@ spec:
args: [/etc/os-release]
```

## `withParams` example from another step in the workflow
Finally, the most powerful form of this is to generate that JSON array of objects dynamically in one step, and then pass it to the next step so that the number and values used in the second step are only calculated at runtime.

```yaml
Expand Down

0 comments on commit 68ae239

Please sign in to comment.