Looping
Learn how to use loops in Taskfile to iterate over lists and execute commands multiple times.
Loop a static list / Loop the tasks
Assuming you have a Taskfile with a task to build the Docker images. You can use a loop to iterate over a static list of applications and build each one.
Loop a matrix
You can also loop over a matrix of values. This is useful when you have multiple variables that need to be combined in each iteration.
You can also reference the matrix to other variables as long as they are lists.
This will generate the following images:
app1:latest
app1:v1.0
app2:latest
app2:v1.0
Loop the task's sources
or generated
files
It is the same concept as above, but you can use the sources
or generated
files to loop over a list of files.
Loop the variables
If you want to loop over the variables, you can use the vars
keyword. This is useful when you have a list of variables that need to be iterated over.
Loop and rename variables
When you loop over a list of variables, you can also rename the variables using the as
keyword.
Loop the dependencies
Remember deps
are run in parallel, so the iterations are not guaranteed to run in order.