Jonah Duffin
07/21/2025, 2:34 PMpull:
- prefect.deployments.steps.run_shell_script:
Marvin
07/21/2025, 2:34 PMMarvin
07/21/2025, 2:36 PMrun_shell_script
steps in a prefect.yaml
file:
1. First, you'll need to install the shell integration:
bash
pip install "prefect[shell]"
2. Yes, you can use custom blocks in a run_shell_script
step in your prefect.yaml
. There are two main approaches:
### Option 1: Using Block References
yaml
pull:
- prefect.deployments.steps.run_shell_script:
script: |
echo "Using block: {{ my_custom_block.some_field }}"
env:
SOME_VAR: "{{ my_custom_block.some_field }}"
### Option 2: Using Block Loading
yaml
pull:
- prefect.deployments.steps.run_shell_script:
script: |
echo "Using block: {{ prefect.blocks.my-block-type.block-name.some_field }}"
To make this work:
1. Your custom block must be registered with Prefect first:
bash
prefect block register --module your_module.blocks
2. Create an instance of your block either through the UI or programmatically.
3. In your prefect.yaml
, you can reference block values using the templating syntax {{ }}
. The block values will be expanded when the deployment step runs.
Important Notes:
- Make sure your custom block is properly registered and available in the Prefect server
- The block must be accessible in the environment where the deployment runs
- Values are expanded at runtime, so make sure any sensitive information is properly handled
- The exact fields you can reference depend on your custom block's structure
If you need help with a specific block type or field, please share more details about your custom block's structure and I can provide more targeted guidance.Jonah Duffin
07/21/2025, 4:23 PM- prefect.deployments.steps.run_shell_script:
id: vgt-install
script: |
export ARTIFACTORY_UW2_USER="{{ prefect.blocks.secret.artifactory-uw2-user }}"
export ARTIFACTORY_UW2_API_TOKEN="{{ prefect.blocks.secret.artifactory-uw2-api-token }}"
pip install --upgrade --pre -i "https://${ARTIFACTORY_UW2_USER}:${ARTIFACTORY_UW2_API_TOKEN}@artifactory-uw2.mycompany.com/artifactory/api/pypi/my-pypi-index" my_package
stream_output: true
With an error like this:
Invalid template. Only a single block placeholder is allowed in a string and no surrounding text is allowed.
What is the correct way to pass more than one block value to a single command?Marvin
07/21/2025, 4:23 PMMarvin
07/21/2025, 4:24 PMyaml
- prefect.deployments.steps.run_shell_script:
id: vgt-install
script: |
pip install --upgrade --pre -i "https://$ARTIFACTORY_USER:$ARTIFACTORY_TOKEN@artifactory-uw2.mycompany.com/artifactory/api/pypi/my-pypi-index" my_package
env:
ARTIFACTORY_USER: "{{ prefect.blocks.secret.artifactory-uw2-user }}"
ARTIFACTORY_TOKEN: "{{ prefect.blocks.secret.artifactory-uw2-api-token }}"
stream_output: true
Key changes:
1. Moved the block references to the env
section where each environment variable can have a single block reference
2. Referenced these environment variables in the script using $ARTIFACTORY_USER
and $ARTIFACTORY_TOKEN
3. Removed the export
statements as they're not needed - the env
section handles this for you
This approach works because:
- Each environment variable in the env
section can contain exactly one block reference
- The environment variables are then available to your script
- The templating restriction of "single block placeholder with no surrounding text" is satisfied
This is the recommended pattern when you need to use multiple block values in a single command or script.