<@ULVA73B9P> I have a prefect deployment defined u...
# ask-marvin
t
@Marvin I have a prefect deployment defined using a yaml file. The deployment pulls from git using
prefect.deployments.steps.git_clone
, which points at the project's main branch. How can I modify my yaml file so that I can trigger jobs that point at another, custom, branch?
m
thought for 388.2 seconds
Great question. In Prefect 3.x, the easiest way to make your git branch configurable at run time is to template the
git_clone
step’s
branch
(or
commit_sha
) from an environment variable, then pass that env var as a job variable when you trigger the run. Here’s how to update your `prefect.yaml`: - Template the branch with an env var, falling back to main if it’s not set. - You can also add an optional
commit_sha
if you want to pin to a specific commit instead of a branch. Example snippet:
Copy code
deployments:
  - name: my-deployment
    entrypoint: flows/my_flow.py:my_flow
    pull:
      - prefect.deployments.steps.git_clone:
          repository: <https://github.com/your-org/your-repo.git>
          branch: "{{ env.GIT_BRANCH | default('main') }}"
          # Or pin by commit instead of branch:
          # commit_sha: "{{ env.GIT_SHA }}"
    work_pool:
      name: your-work-pool
Then, when you want to run against a different branch, pass the env var via job variables at run time:
Copy code
prefect deployments run "my_flow/my-deployment" --job-variable 'env={"GIT_BRANCH":"feature/my-branch"}' --watch
Notes: -
--job-variable
values are JSON; keep the quoting as shown. - Only set one of
branch
or
commit_sha
at a time. - You can also fix branches by defining multiple deployments in the same
prefect.yaml
(one per branch), if you prefer named, static deployments. References: - Git clone step parameters (supports
branch
and
commit_sha
): prefect.deployments.steps.git_clone - Prefect YAML and templating basics: prefect.yaml guide