Skip to main content

prefect.deployments.steps.utility

Utility project steps that are useful for managing a project’s deployment lifecycle. Steps within this module can be used within a build, push, or pull deployment action. Example: Use the run_shell_script setp to retrieve the short Git commit hash of the current repository and use it as a Docker image tag:

Functions

run_shell_script

Runs one or more shell commands in a subprocess. Returns the standard output and standard error of the script. Args:
  • script: The script to run
  • directory: The directory to run the script in. Defaults to the current working directory.
  • env: A dictionary of environment variables to set for the script
  • stream_output: Whether to stream the output of the script to stdout/stderr
  • expand_env_vars: Whether to expand environment variables in the script before running it
  • shell: Whether to run the command through the system shell. When True, shell operators like pipes (|), redirects (>), and logical operators (&&, ||) are supported. Only set this to True when you need shell features, as it has security implications similar to subprocess.run(shell=True).
Returns:
  • A dictionary with the keys stdout and stderr containing the output of the script
Examples: Retrieve the short Git commit hash of the current repository to use as a Docker image tag:
Run a multi-line shell script:
Run a shell script with environment variables:
Run a shell script with environment variables expanded from the current environment:
Run a shell script in a specific directory:
Run a script stored in a file:
Run a command that uses shell operators like pipes:

pip_install_requirements

Installs dependencies from a requirements.txt file. Args:
  • requirements_file: The requirements.txt to use for installation.
  • directory: The directory the requirements.txt file is in. Defaults to the current working directory.
  • stream_output: Whether to stream the output from pip install should be streamed to the console
Returns:
  • A dictionary with the keys stdout and stderr containing the output the pip install command
Raises:
  • subprocess.CalledProcessError: if the pip install command fails for any reason

Classes

RunShellScriptResult

The result of a run_shell_script step. Attributes:
  • stdout: The captured standard output of the script.
  • stderr: The captured standard error of the script.