Loops can be implemented within a workflow to repeat a set of tasks based on defined conditions.
Loops execute in sequence. A maximum of 4 steps can run in parallel.
Loop configuration is accessed in either the tab of a block configuration, or by right-clicking a block and selecting .
Loop settings require a list of things to operate on:
-
Plain, single values, which are then usable in task parameters such as
{{ @item }}. -
A .JSON object where each element in the object can be addressed by its key such as
{{ @item.key }}.
Accessing the aggregate results of a loop
The output of all iterations can be accessed as a .JSON array once a loop is completed. The output of each iteration must be a valid .JSON file.
There are four loop types that can be defined and are selected in the field:
-
withSequence
-
withItems
-
withComplexItems
-
withParam
The withSequence loop enables an iteration over a sequence of numbers or the generation of a range of values within a workflow.
It can be used for repeating a set of steps a specific number of times or performing operations based on a range of values.
To create a sample withSequence loop, follow these steps:
-
Select an empty block and open the configuration.
-
Click Edit loop.
configuration options are presented.
-
From the field, select withSequence.
-
Enter the number of loop iterations to the field.
-
Optionally, enter a value the loop should start from and/or end with.
-
Click Save loop.
-
From the configuration, click Edit parameters.
Configuration options are presented.
-
In the field, enter
{{ @item }}and click Save parameters.This value will be converted at runtime.
For example, if count is set to 3 and the start value is 2, the results of this loop will be:
-
loop list => ["2", "3", "4"] -
{{ @item }} => 2or3or4, based on the iteration
The withItems loop enables iteration over a list of items.
It can be used when needing to perform operations based on a list of items.
To create a sample withItems loop, follow these steps:
-
Select an empty block and open the configuration.
-
Click Edit loop.
configuration options are presented.
-
From the field, select withItems
-
Enter
enin the field and click +Item (another field is created). -
Enter
dein the second field and create a third field. -
Enter
frin the third field and create a fourth field. -
Enter
usin the fourth field. -
Click Save loop.
-
From the configuration, click Edit parameters.
Configuration options are presented.
-
In the field, enter
{{ @item }}and click Save parameters.This value will be converted at runtime.
The results of this loop will be an iteration over a list of language codes:
-
loop list => ["en", "de", "fr", "ua"] -
{{ @item }} => enorde .. ua
The withComplexItems loop enables iterating over a list of objects.
It can be used when needing to perform operations based on a list of complex items.
To create a sample withComplexItems loop, follow these steps:
-
Select an empty block and open the configuration.
-
Click Edit loop.
configuration options are presented.
-
From the field, select withComplexItems
-
Click +Key:value to add a second key.
-
For , enter the following:
-
-
: name
-
: Project 1
-
-
-
: id
-
: 11
-
-
-
Click +Object to add a second object and +Key:value for a second key.
-
For , enter the following:
-
-
: name
-
: Project 2
-
-
-
: id
-
: 22
-
Settings sample:
-
-
From the configuration, click Edit parameters.
Configuration options are presented.
-
In the field, enter
{{ @item.name }}and click Save parameters. This value will be converted at runtime.
The results of this loop will be an iteration over a list of projects:
-
loop list=>[ { "name": "Project 1", "id": 11 }, { "name": "Project 2", "id": 22 } ] -
{{ @item }}=>{ "name": "Project 1", "id": 11 } -
{{ @item.name }}=>Project 1 -
{{ @item.id }}=>11
The withParam loop enables iteration over a dynamic list which is output from any previous task or trigger.
This loop is just used as a reference in the parameter field.
Example:
Outputs of task (Strings: Publish a release):
{
"created_at": "2015-01-28T09:52:53Z",
"environments": ["development", "production"],
"id": "abcd1234cdef1234abcd1234cdef1234",
"locales": [
{
"code": "en-GB",
"id": "abcd1234cdef1234abcd1234cdef1234",
"name": "English"
},
{
"id": "abcd5678cdef5678abcd5678cdef5678",
"name": "German",
"code": "de_DE"
}
],
"platforms": ["android"],
"project": {
"created_at": "2015-01-28T09:52:53Z",
"id": "abcd1234cdef1234abcd1234cdef1234",
"main_format": "xml",
"name": "My Android Project",
"updated_at": "2015-01-28T09:52:53Z"
},
"updated_at": "2015-01-28T09:52:53Z",
"version": 1
}
If loop settings is set with {{ $.locales }}, then:
-
loop list=>[ { "code": "en-GB", "id": "abcd1234cdef1234abcd1234cdef1234", "name": "English" }, { "id": "abcd5678cdef5678abcd5678cdef5678", "name": "German", "code": "de_DE" } ] -
First
{{ @item }}=>{ "code": "en-GB", "id": "abcd1234cdef1234abcd1234cdef1234", "name": "English" } -
{{ @item.code }}=>en-GB -
{{ @item.name }}=>English
Or if {{ $.environments }} is referenced, then:
-
loop list=>["development", "production"] -
{{ @item }}=>developmentorproduction