benorbital
05/17/2024, 12:56 PM{{$(git rev-parse --abbrev-ref HEAD)}}
in several places in my prefect.yaml. Is there a way of defining this once and then referencing back to it?Marvin
05/17/2024, 12:56 PMprefect.yaml
and then reference it multiple times throughout the same file. This variable will be evaluated at runtime for the deployed flow.
To define and use a variable in prefect.yaml
deployment steps, you can follow this pattern:
yaml
# Define the variable
variables:
my_variable_name: "Value of the variable"
# Use the variable later in the file
tasks:
- task_name:
parameter: "{{ prefect.variables.my_variable_name }}"
For your specific case, you might want to define a variable for the git branch like this:
yaml
variables:
git_branch: "{{$(git rev-parse --abbrev-ref HEAD)}}"
pull:
- prefect.deployments.steps.git_clone:
repository: <https://github.com/PrefectHQ/hello-projects.git>
branch: "{{ prefect.variables.git_branch }}"
Everywhere else in your prefect.yaml
where you need to reference the git branch, you can use {{ prefect.variables.git_branch }}
.
For more details on how to use variables and templating in prefect.yaml
, follow these links:
- Using Variables in prefect.yaml
- Prefect Deployments Guide
- Prefect Settings Guide
Please note that the syntax provided might need to be adjusted depending on the specific context and Prefect version you are using. The above examples are meant to illustrate the concept and may not be copy-paste ready.