# Setting environment variables for test and development

**URL:** https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709
**Category:** Development
**Created:** [January 15, 2020, 5:51pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709 "2020-01-15T17:51:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [January 15, 2020, 5:51pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/1 "2020-01-15T17:51:57Z")

</div>

I’m thinking of adding the dotenv gem ([GitHub - bkeepers/dotenv: A Ruby gem to load environment variables from `.env`. · GitHub](https://github.com/bkeepers/dotenv)) to my plugin for testing and development purposes. This is so that I can easily set my environment variables per environment.

I was wondering if I’m missing something and there’s a better way of achieving this?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [January 15, 2020, 6:40pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/2 "2020-01-15T18:40:15Z")

</div>

What are you trying to load? You can set

DISCOURSE\_SETTING\_NAME=value

for all SiteSettings.

Would that help?

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [January 15, 2020, 7:14pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/3 "2020-01-15T19:14:45Z")

</div>

Unfortunately not. I’m working on a private plugin and need to set an environment variable for sensitive data so that I’m not checking it into source control.

It’s fine setting that environment variable on the production server, but I want to be able to load this into the test environment when running tests for example. I could specify it inline, but ideally I’d want a more scalable solution.

The reason I posted is because adding that gem feels wrong, I would have assumed that Discourse would already have a solution for this problem.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [January 15, 2020, 7:18pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/4 "2020-01-15T19:18:44Z")

</div>

Then I think you can set envs like

```
 DISCOURSE_MY_PLUGIN_SETTING

```

For tests, I think you might set `GlobalSetting.my_plugin_setting` in the spec, but that’s mostly a wild guess.

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [January 15, 2020, 7:22pm UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/5 "2020-01-15T19:22:29Z")

</div>

Thanks, I will take a look at `GlobalSetting`

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [July 6, 2020, 11:07am UTC](https://meta.discourse.org/t/setting-environment-variables-for-test-and-development/138709/6 "2020-07-06T11:07:20Z")

</div>

You can set `ENV['yourkey'] = 'yourval'` in your plugin and that works. I used it just today to test my code.

Also, you can install gems specific to modes. I haven’t tried it myself yet but here’s an example. [discourse-assign/Gemfile at main · discourse/discourse-assign · GitHub](https://github.com/discourse/discourse-assign/blob/master/Gemfile)
