In my rails app, i set response header from env:
response.headers['application-version'] = ENV["APPLICATION_VERSION"]
I try set env variable in capistrano deploy file, but this don't work.
set :default_environment, {
'APPLICATION_VERSION' => Time.now.strftime('%Y%m%d%H%M%S%L')
}
How i set env variable on deploy?
Setting default_environment (or default_env for Capistrano 3.x) will only set the variables during deploy commands. From the docs:
A hash that can be used to set environment variables that should be present for all commands that are executed.
If you want to set environment variables to be used by your rails server---which is another process, another vm instance, in another login session---you need to set the env variables for the session its being executed, e.g. via .bashrc, .profile, .zshrc or whatever shell you're using. You can also use some environment variable manager like direnv, rbenv-vars, etc.
Hope that helps.
In one Rails app, I use Capistrano 3. I set my variables with default_env
set :default_env, {
'APPLICATION_VERSION' => Time.now.strftime('%Y%m%d%H%M%S%L')
}
For another Rails app, I use Capistrano 2. There I use :default_environment to set variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With