Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variable in Gemfile

I'm having trouble using an environment variable in my Gemfile.
I'm trying to load a gem from a private Github repository with an API key:

auth = ENV['SECRET_GIT']
gem 'foobar', git: "https://#{auth}:[email protected]/Foo/Bar.git"

But if I puts my ENV['SECRET_GIT'] variable, there's nothing in it.
I though you could do it this way because of these (especially the first one):
- https://devcenter.heroku.com/articles/bundler-configuration#gem-source-username-and-password
- https://stackoverflow.com/a/7338154/5353193
- Deploying to Heroku with environment variables in Gemfile

Bundler version 1.14.6
ruby 2.4.0p0

Thank you for you help

EDIT
I'm trying to do this in my local environment, I guess there would be no problem doing this on heroku.

like image 210
Francois Avatar asked Oct 30 '22 10:10

Francois


1 Answers

Well yes you can set it from console

heroku config:set SECRET_GIT=your-api-key

Or, you can set the environment variables from heroku dashbord

heroku > your-app > settings > Config variables

And add a new entry

SECRET_GIT = your-api-key

And now you can use it directly in Gemfile

gem 'foobar', git: "https://#{ENV['SECRET_GIT']}:[email protected]/Foo/Bar.git"
like image 173
Deepak Mahakale Avatar answered Nov 15 '22 07:11

Deepak Mahakale