-
-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple commands in a task for loop #1306
Comments
I'm not a huge fan of the multi-nested If you need to loop over multiple commands, why not just wrap up your functionality in a separate task? This means that if you ever need to run that set of commands for a single item or a different set of items, then your Taskfile will already support it. e.g. version: '3'
tasks:
do-thing-for-all-platforms:
cmds:
- for:
var: PLATFORM
split: ','
task: do-thing-for-platform
vars:
PLATFORM: {{.ITEM}}
do-thing-for-platform:
cmds:
- task: build
vars:
PLATFORM: '{{.PLATFORM}}'
- echo 'Do things with platform {{.PLATFORM}}'
build:
cmds:
- echo 'hit {{.PLATFORM}}' It's also worth remembering that if you don't want certain tasks to be executable via the CLI, you can add do-thing-for-platform:
internal: true
cmds:
- ... |
While I still prefer the former, my workaround was essentially what you showed. Currently our task files are getting pretty complex. We have a library of different task files for inclusion, indirection points (multiple includes), etc. I like my suggestion better because it reduces the amount of spaghetti - one less task - but this is not a critical item. Thanks! |
I'm going to decline this for now for the reasons I gave above. |
I would like to be able to specify a list of commands inside of a task for loop.
This is useful if the second
cmd
relies on an output of the firstcmd
, but each iteration of the firstcmd
overwrites prior iterations. This is useful if, for instance, the first cmd loads theexample:latest
image of platformarm
into the local docker daemon, and then the second command execs some tests against it. Because other image platforms would have the same name and tag (in the case of a multiplatform manifest), it would overwrite prior work locally and cause a mismatch when testing.For example:
Expected Output:
Instead you need to do something like:
Actual Output:
The way I read it this is similar to but different from #1299
The text was updated successfully, but these errors were encountered: