9_ake
9_ake
TTask
Created by 9_ake on 3/16/2025 in #help
How can I create an internal task which will generate env variables for the main task?
Hello everyone! I am using Taskfile as a short cli helper to run my tests. Each time I am running task, i have to generate new env variables, is there a way to do smth similar via a sub-task? For example:
gen-env:
env:
SERVER_PORT:
sh: my-random unused-port
TEMP_FILE:
sh: my-random tempfile
ADDRESS: "localhost:{{.SERVER_PORT}}"

test-iter-1:
deps: [ linter, unit-tests, build ]
cmds:
- task: gen-env
- >-
metricstest -test.v -test.run=^TestIteration1$ \
-temp-file={{.TEMP_FILE}} \
-address={{.ADDRESS}} \
-server-port={{.SERVER_PORT}} \
-source-path=.
gen-env:
env:
SERVER_PORT:
sh: my-random unused-port
TEMP_FILE:
sh: my-random tempfile
ADDRESS: "localhost:{{.SERVER_PORT}}"

test-iter-1:
deps: [ linter, unit-tests, build ]
cmds:
- task: gen-env
- >-
metricstest -test.v -test.run=^TestIteration1$ \
-temp-file={{.TEMP_FILE}} \
-address={{.ADDRESS}} \
-server-port={{.SERVER_PORT}} \
-source-path=.
Due to a large amount test-iter-* tasks it's really annoying to copy all same env variables... Thank you for any help and suggestions!
1 replies