You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku发布阶段执行Shell脚本失败问题排查求助

Troubleshooting Heroku Release Phase Failures for Django Projects

Let’s walk through how to fix your release phase issue step by step—this is a super common problem, so we’ll narrow it down quickly.

First: Fix Procfile Syntax & Typos

You mentioned trying bash $PWD/releash.sh, but your script is named release.sh (note the missing "a" in your command!). That’s an easy typo that could break everything.

Your Procfile should live in the root of your Django project, and the release line should look like one of these (both work):

# Option 1: Directly execute the script (requires executable permissions)
web: gunicorn your_project_name.wsgi
release: ./release.sh

# Option 2: Explicitly call bash (good if you want to avoid permission issues temporarily)
web: gunicorn your_project_name.wsgi
release: bash release.sh

Heroku runs commands from your app’s root directory by default, so you don’t need $PWD—it’s redundant here.

Second: Ensure Your Script Has Executable Permissions

Heroku can’t run your script if it doesn’t have execute rights. On your local machine, run this command:

chmod +x release.sh

Then commit this change to Git (file permissions are tracked in Git) and push to Heroku again. This fixes the "permission denied" error that’s often the root cause.

Third: Validate Your release.sh Script Content

Make sure your script starts with a shebang line to tell Heroku which shell to use:

#!/bin/bash
set -e  # Optional but recommended: exit immediately if any command fails

Then add your Django commands—for example:

# Run database migrations
python manage.py migrate --noinput

# Collect static files (if you use Django's staticfiles)
python manage.py collectstatic --noinput

Avoid absolute paths here—Heroku’s environment uses relative paths from your app root, so stick to commands like python manage.py ... (Heroku will use the correct Python executable from your runtime).

Fourth: Check Heroku’s Release Logs for Exact Errors

The most helpful step is to look at the actual error message from Heroku. Run this command in your terminal:

heroku logs --ps release

This will show you exactly why the release phase failed:

  • If you see "release.sh: not found", it’s either a path/typo issue or missing executable permissions.
  • If you see errors from manage.py, it’s a Django-specific problem (like a missing environment variable, or a migration that fails locally too).

Fifth: Test the Script Locally

Before pushing to Heroku, run the script in your local Django environment to make sure it works:

./release.sh

If it fails locally, fix those issues first—Heroku will have the same problem.


内容的提问来源于stack exchange,提问作者Nicholas Kajoh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:07:52