我有一个看起来像这样的 app.json(大致):
{
"addons": [
"heroku-postgresql"
],
"env": {
"RAILS_MASTER_KEY": {
"description": "Key to decrypt Rails credentials.",
"require": true,
"generator": "secret"
},
"SAFE_EMAIL_DEST": {
"description": "Where to send emails when in safe mode.",
"required": false
}
},
"environments": {
"test": {
"scripts": {
"test": "bundle exec rake spec"
}
},
"staging": {
"env": {
"SAFE_EMAIL_DEST": "staging@example.com"
}
},
"production": {
}
}
}
但是当我运行应用程序时,出现错误:RuntimeError (SAFE_EMAIL_DEST needs to be defined)
意思是,该环境变量未定义。
我错过了什么?为什么没有被定义? “暂存”是 Heroku 管道中处于暂存状态的应用的正确环境名称吗?
答案 0 :(得分:0)
对于 app.json 中的 environments
键,平台只能识别 2 个:
test
:应用于由 Heroku CI 创建的持续集成环境。review
:应用于由 Heroku Review Apps 创建的 Review Apps 环境。所以基本上你需要直接在 env
键中设置你的 "SAFE_EMAIL_DEST"
变量:
{
"addons": [
"heroku-postgresql"
],
"env": {
"RAILS_MASTER_KEY": {
"description": "Key to decrypt Rails credentials.",
"require": true,
"generator": "secret"
},
"SAFE_EMAIL_DEST": {
"description": "Where to send emails when in safe mode.",
"value": "staging@example.com"
}
},
"environments": {
"test": {
"scripts": {
"test": "bundle exec rake spec"
},
"env": {
"SAFE_EMAIL_DEST": "Your SAFE_EMAIL_DEST for continuous integration environments"
}
}
}
}