Hey <@ULVA73B9P> do Prefect set an env var by defa...
# ask-marvin
r
Hey @Marvin do Prefect set an env var by default that will let me know a job is running with Prefect? This is for Prefect 2.x
m
In Prefect 2.x, there doesn't appear to be a default environment variable specifically set to indicate that a job is running with Prefect. Instead, you can manage job-specific environment variables by configuring them in the deployment definition within the
prefect.yaml
file. These variables can be used to pass necessary information to your deployment. Here's an example based on the documentation:
Copy code
yaml
deployments:
- name: demo-deployment
  entrypoint: demo_project/demo_flow.py:some_work
  work_pool:
    name: local
  job_variables:
    env:
      EXECUTION_ENVIRONMENT: "your_value"
      MY_NOT_SO_SECRET_CONFIG: "your_value"
In this setup, you can specify any environment variable you need for your deployment, but there's no specific default variable that Prefect sets to indicate the job is running. You would have to define such behavior yourself if needed. For more details, you can visit the deployment guide here.
n
hi @Robert - are you asking about: • specifically local runs? (not necessarily I think) • specifically runs of a deployment? (yes) • either?
r
Hi Nate! • I'm not sure what you mean by local runs. But also the coffee hasn't kicked in yet :p • yes, runs of a deployment
n
by local run, I just meant if you just run a flow in a python file, which is not necessarily deployed, i could have been more precise. cool! so the answer is yes, there are env vars we set, for example
PREFECT__FLOW_RUN_ID
but i’d be curious if you need specifically an env var or just some signal that you’re in a run? because accessing prefect.runtime.deployment would probably be safer / more future proof
r
Just some signal that we're in a run. Thanks for the pointer!