<@ULVA73B9P> in the prefect.yaml, how can I includ...
# ask-marvin
f
@Marvin in the prefect.yaml, how can I include environmental variables?
m
thought for 532.8 seconds
Great question! In Prefect 3.x, you add environment variables for your flow runs in the prefect.yaml under each deployment’s work pool job_variables. The env field is a simple key/value mapping (dictionary). Prefect will pass these to the process/container/pod that executes your flow. Here are concise examples for common work pool types. Process work pool
Copy code
deployments:
  - name: my-process-deployment
    entrypoint: flows/flow.py:my_flow
    work_pool:
      name: my-process-pool
      job_variables:
        env:
          LOG_LEVEL: INFO
          FEATURE_FLAG_X: "true"
Docker work pool
Copy code
deployments:
  - name: my-docker-deployment
    entrypoint: flows/flow.py:my_flow
    work_pool:
      name: my-docker-pool
      job_variables:
        image: myrepo/myimage:latest
        env:
          ENVIRONMENT: prod
          API_BASE_URL: <https://api.example.com>
Kubernetes work pool - You can set simple key/value env vars via job_variables.env. - If you need valueFrom (e.g., secretKeyRef), add it in job_variables.job_manifest.
Copy code
deployments:
  - name: my-k8s-deployment
    entrypoint: flows/flow.py:my_flow
    work_pool:
      name: my-k8s-pool
      job_variables:
        image: myrepo/myimage:latest
        namespace: default
        service_account_name: my-service-account
        env:
          SIMPLE_VAR: hello
        job_manifest:
          spec:
            template:
              spec:
                containers:
                  - name: prefect-job
                    env:
                      - name: SECRET_FROM_K8S
                        valueFrom:
                          secretKeyRef:
                            name: my-secret
                            key: password
Notes and tips - No automatic ${ENV_VAR} expansion: prefect.yaml does not automatically expand shell-style env variables in-place. Put literal strings in env or ensure the worker’s runtime environment already has the variables set. - Work pool defaults vs deployment overrides: You can set default env at the work-pool level (in the UI or via the base job template). Values in a deployment’s job_variables will override/extend those defaults. - Kubernetes merging: job_variables.env is rendered into the pod’s container env list. If you also specify env entries in job_manifest, those are merged; explicit entries in the manifest take precedence on conflicts. Docs - Prefect YAML overview: prefect.yaml guide - Job variables (env, image, etc.): Customize job variables - Settings and profiles (.env for Prefect settings): Settings and profiles If you share which work pool you’re using (process, docker, kubernetes) and whether you need to pull from secrets or your OS environment, I can tailor an exact snippet.