Julien
08/04/2025, 10:22 AMMarvin
08/04/2025, 10:22 AMMarvin
08/04/2025, 10:23 AMprefect.yaml
file for a run_shell_script
step:
1. First, ensure you have created a Secret block in Prefect with your sensitive data. You can do this via the UI or using Python.
2. In your prefect.yaml
, you can reference the secret in the job_variables
section under the specific deployment. Here's an example:
yaml
deployments:
- name: my-deployment
job_variables:
env:
MY_SECRET_ENV: "{{ prefect.blocks.secret.my-secret-block-name.get() }}"
work_pool:
name: my-work-pool
flow:
path: ./flow.py
# If using run_shell_script step
actions:
- name: run-my-script
run_shell_script:
script: ./my_script.sh
env:
SCRIPT_SECRET: "{{ prefect.blocks.secret.my-secret-block-name.get() }}"
There are two ways to handle this:
1. Global deployment level: Setting the environment variable in job_variables.env
makes it available to all steps in the deployment
2. Step-specific level: Setting it directly in the run_shell_script.env
section makes it available only to that specific step
Important notes:
- Replace my-secret-block-name
with the actual name of your secret block
- The secret value will be resolved at runtime
- Make sure your worker has access to the secret block
- You can reference multiple secrets by creating multiple environment variables
If you need to reference an existing environment variable that's already set in your environment, you can use:
yaml
job_variables:
env:
MY_ENV_VAR: "{{ $EXISTING_ENV_VAR }}"
Would you like me to provide more specific examples or clarify any part of this explanation?