brief-family-9488
08/05/2025, 6:01 PMjolly-florist-66728
08/05/2025, 6:01 PMjolly-florist-66728
08/05/2025, 6:02 PMenv
parameter in each @task
decorator. This ensures the environment variable is propagated to all task containers at runtime. For example:
from flytekit import task, workflow
@task(env={"MY_ENV_VAR": "my_value"})
def t1():
...
@task(env={"MY_ENV_VAR": "my_value"})
def t2():
...
@workflow
def wf():
t1()
t2()
This approach is supported and will apply the environment variable to all components of tasks, including those using plugins like Dask. There is currently no built-in way to set an environment variable globally for all tasks in a workflow without specifying it in each task decorator. Would you like more detail or examples for specific plugins or advanced use cases?
Sources:
- Flyte Dask Plugin README 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.brief-family-9488
08/05/2025, 6:49 PMjolly-florist-66728
08/05/2025, 6:49 PMjolly-florist-66728
08/05/2025, 6:50 PMenv
in the @task
decorator.
from flytekit import task
from flytekitplugins.dask import Dask
@task(
task_config=Dask(),
env={"FOO": "BAR"}
)
def my_dask_task():
# FOO=BAR will be available in all Dask pods
...
This ensures the variable is available across the distributed Dask cluster created for the task.
Reference
2. Dynamic Workflows:
If you generate tasks dynamically, you can use the .with_overrides()
method to set environment variables at invocation time:
from flytekit import task, workflow, dynamic
@task
def t(x: int) -> int:
...
@dynamic
def dyn_wf():
for i in range(3):
t(x=i).with_overrides(env={"MY_ENV": str(i)})
@workflow
def wf():
dyn_wf()
Each dynamic task instance gets its own environment variable value.
3. PodTemplate for Custom Pods:
For more complex pod-level configuration (e.g., sidecars, shared volumes, or global env vars), use a Kubernetes PodTemplate and reference it in your task:
@task(pod_template="my-pod-template")
def t():
...
Define the PodTemplate with the desired environment variables and mount it in your Flyte deployment.
Reference
Let me know if you want more details on any of these, or examples for other plugins.
Sources:
- Flyte Dask Plugin README
- Reference 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.