When during the slug build process does my rails app have access to the ENV variables set by Heroku? When during the slug build process does my rails app have access to the ENV variables set by Heroku? heroku heroku

When during the slug build process does my rails app have access to the ENV variables set by Heroku?


I have received a response from Heroku support which seems to fix the needs that I am looking for.

Heroku's response:

Unfortunately, at this point, our dyno metadata lab flags and the config vars made available during the build don't entirely match up. During the build, you can use the SOURCE_VERSION environment variable, which will be the commit hash. Then, at runtime, you can use HEROKU_SLUG_COMMIT to get the same value.

The reason behind this difference is mostly a difference of context. Naming that variable HEROKU_SLUG_COMMIT during build wouldn't make sense, as it's not a slug yet.

Since we will never set both config vars, you should be able to use any of them, and fallback to the other if it's not set.

My current implementation now is:ENV["SOURCE_VERSION"] || ENV['HEROKU_SLUG_COMMIT'] in that order. This works for me.


I have solved this for myself by using a deploy script and using the heroku-cli tool to update my app with the new commit hash before pushing the code:

deploy.sh

...heroku config:set APP_VERSION=<commit hash> --app <your app name>git push heroku master...