<@ULVA73B9P> is it possible to have conditional va...
# ask-marvin
f
@Marvin is it possible to have conditional variables in the prefect.yaml file?
m
It is possible to use variables in the
prefect.yaml
file, but they are evaluated at runtime rather than being true conditional variables like you might find in a programming language. You can reference these variables using the special syntax
{{ prefect.variables.variable_name }}
. ### Example Usage: You can use variables to templatize deployment steps, as shown below:
Copy code
yaml
pull:
  - prefect.deployments.steps.git_clone:
      repository: <https://github.com/PrefectHQ/hello-projects.git>
      branch: "{{ prefect.variables.deployment_branch }}"
In this example, the
deployment_branch
variable will be evaluated at runtime, allowing you to change its value without updating the deployment directly. For more details, you can refer to the Prefect documentation on variables and Prefect deployment guides. It seems we don't have related issues in the GitHub repository for more specific conditional uses, which implies there's not much discussion or feature requests on this topic at the moment. If you have additional questions or need further examples, feel free to ask.
f
@Marvin how can I use variable in prefect.yaml in the context of CI/CD ? I don't have access to Prefect variables in this context
m
In the context of CI/CD, where you might not have access to Prefect variables, you can make use of environment variables within the
prefect.yaml
file. Here's how you can achieve this: ### Using Environment Variables You can template environment variables in your
prefect.yaml
file using the
{{ $ENV_VAR_NAME }}
syntax. This allows you to leverage environment variables that are already set in your CI/CD pipeline. ### Example:
Copy code
yaml
deployments:
  - name: demo-deployment
    entrypoint: demo_project/demo_flow.py:some_work
    work_pool:
      name: local
    job_variables:
      env:
        EXECUTION_ENVIRONMENT: "{{ $EXECUTION_ENVIRONMENT }}"
        MY_NOT_SO_SECRET_CONFIG: "{{ $MY_NOT_SO_SECRET_CONFIG }}"
    schedule: null
In this example: -
EXECUTION_ENVIRONMENT
and
MY_NOT_SO_SECRET_CONFIG
will be pulled from the environment variables set in your CI/CD pipeline. - This templating will allow you to modify the values without hard coding them in the
prefect.yaml
file. You can read more about this in the Prefect Documentation on overriding job variables. If you have additional queries or need further assistance, feel free to ask.