Lucas Silvestre
11/06/2025, 7:03 PMMarvin
11/06/2025, 7:03 PMMarvin
11/06/2025, 7:07 PMPREFECT_GIT_COMMIT_SHA isn’t something Prefect sets for you. If it’s empty, it just isn’t defined in the environment where you’re running prefect deploy.
You’ve got a few ways to fix it (any one of these will work):
1) Set it before you run prefect deploy
- Bash:
export PREFECT_GIT_COMMIT_SHA=$(git rev-parse --short HEAD)
prefect deploy
- PowerShell:
$env:PREFECT_GIT_COMMIT_SHA = (git rev-parse --short HEAD)
prefect deploy
2) Compute it inside your build steps and reference the step output
build:
- prefect.deployments.steps.run_shell_script:
id: get-sha
script: "git rev-parse --short HEAD"
- prefect_docker.deployments.steps.build_docker_image:
id: build-image
requires: prefect-docker>=0.6.0
image_name: "{{ prefect.blocks.secret.docker-image }}"
tag: "reports-analytics-{{ get-sha.stdout }}"
dockerfile: ../Dockerfile
platform: "linux/amd64"
3) Use your CI’s built-in commit SHA variable instead
- GitHub Actions:
tag: "reports-analytics-{{ $GITHUB_SHA }}"
Or explicitly set your variable:
- name: Deploy
run: |
export PREFECT_GIT_COMMIT_SHA=${{ github.sha }}
prefect deploy
- GitLab CI:
tag: "reports-analytics-{{ $CI_COMMIT_SHA }}"
Notes:
- Build steps run in the environment where you execute prefect deploy. Make sure that environment has git installed and is inside the repo so git rev-parse works.
- Prefect 3.x will use git metadata for deployment versioning if available, but it does not automatically populate PREFECT_GIT_COMMIT_SHA for templating.
Docs for reference:
- Prefect YAML templating and environment variables: prefect.yaml guide
- Run shell script step: run_shell_script step
If you can share where you’re running prefect deploy (local, GitHub Actions, GitLab, etc.), I can give a tailored snippet.