I'm trying to attach job variables to a specific d...
# ask-community
j
I'm trying to attach job variables to a specific deployment run using the UI. When I use
Variable.get("var")
it's null when the flow runs. My job variable for that deployment is
{ "var":"test" )
. Is there a different approach I should take?
n
hi @Jeff S - to disambiguate, Variables.get gives access to a global server side KV and job variables are work pool specific settings
so if you want to smuggle in a value, you can put it in the environment variables section of your job variables on your deployment
job_variables=dict(env=dict(var=42))
j
My deployments are created via the API then run on a schedule. And I was hoping to be able to pass variables to a specific run. How do I access the work pool variables?
To be clear - where do these go and how can I access them when my work pool runs?
Or do I have to deploy initially with any variables I may want to use and then populate them as needed?
whether in yaml or python • you can set whatever job variables you want as a default for the workpool and then override those job variables for deployment or a specific flow run, the set of possible keys for job variables depends on the workpool, but
env
is always there, so you can set something in
env
at deployment or flow run creation time if you want that value and then access it from
os.getenv
(or whatever other thing would use the environment) in your flow run • Variables are a standalone feature that is effectively a global KV, and while job variables can be set to a variable value (that we will render), Variables and job variables arent quite exactly the same thing can you clarify which thing you're looking for?
j
I guess I'm still confused what the UI input box I screenshotted does. I checked the env and I'm not seeing the variables there. But if they should be in the env then I can keep digging in based on that.
Is that only for pre-defined variables?
n
the screenshot shows the custom "create a flow run page" yea?
j
correct
n
cool so that's the job variable overrides for that flow run so maybe you'd want
Copy code
"image": "prefecthq/prefect:3-python3.12"
or instead
Copy code
"env": {"FOO": "bar"}
image
is a job variable on some work pool types (like docker, k8s, ECS ie containerized work pool types)
env
is present on all work pool types, and whatever you put in there will be set as an environment variable in the environment of your eventual flow run https://docs.prefect.io/v3/deploy/infrastructure-concepts/customize
j
ahhhh OK
I need env as the parent. thank you
much appreciated
catjam 1