<@ULVA73B9P> can you please show me an example pay...
# ask-marvin
m
@Marvin can you please show me an example payload for setting job_variables to set environment variables when starting a flow run from a deployment
m
To set environment variables using job_variables in a Prefect deployment, you can add a
job_variables
section to your
prefect.yaml
file. Here is an example payload:
Copy code
deployments:
  - name: demo-deployment
    entrypoint: demo_project/demo_flow.py:some_work
    work_pool:
      name: local
    job_variables:
      env:
        EXECUTION_ENVIRONMENT: staging
        MY_NOT_SO_SECRET_CONFIG: plumbus
    schedule: null
Deploy the flow with these job variables using:
Copy code
prefect deploy -n demo-deployment
For more detailed information, you can refer to the Overriding Job Variables Documentation.
m
@Marvin, I don't want to set variables on my deployment, I want to do it dynamically when starting a flow run from the deployment via the rest API. please show me an example for that.
m
To dynamically set environment variables when starting a flow run from a deployment via the REST API, you can pass job_variables in your API request. Here is an example payload:
Copy code
POST /deployments/{DEPLOYMENT_ID}/create_flow_run
{
  "parameters": {},
  "context": {},
  "labels": [],
  "infrastructure_overrides": {
    "env": {
      "MY_NEW_ENV_VAR": "42",
      "HELLO": "THERE"
    }
  }
}
Replace
{DEPLOYMENT_ID}
with your actual deployment ID. The
infrastructure_overrides
section allows you to specify environment variables dynamically. For more details, refer to the Overriding Job Variables Documentation.
m
Noice