Fabio Geraci
11/26/2025, 1:19 PM_from_ prefect.variables _import_ Variable to retrieve it in my python scriptMarvin
11/26/2025, 1:19 PMMarvin
11/26/2025, 1:22 PMfrom prefect.variables import Variable reads variables stored in Prefect (Cloud/Server), not GitLab. So:
- If your value is defined as a GitLab CI/CD variable, read it as an environment variable in your flow:
import os
from prefect import flow
@flow
def my_flow():
val = os.getenv("MY_GITLAB_VAR") # or os.environ["MY_GITLAB_VAR"]
...
- If you want to use Prefect Variables, create the variable in Prefect (via UI, code, or CLI) and retrieve it with:
from prefect.variables import Variable
val = Variable.get("my_prefect_var", default=None)
You can also sync from GitLab → Prefect at runtime:
import os
from prefect.variables import Variable
gitlab_val = os.getenv("MY_GITLAB_VAR")
if gitlab_val is not None:
Variable.set("my_prefect_var", gitlab_val, overwrite=True)
Notes:
- Prefect Variables are meant for non-sensitive config and are not encrypted; for secrets use Prefect Blocks (e.g., Secret).
- Docs:
- Prefect Variables (concepts)
- How to use Variables
- Blocks and Secrets
If you share a bit more about where your flow runs (e.g., inside a GitLab CI job or elsewhere), I can suggest the cleanest pattern for your setup.