> For the complete documentation index, see [llms.txt](https://docs.rulecube.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rulecube.com/v2.5/how-to-guides/work-with-environment-variables.md).

# Work with (Environment) Variables

## Introduction

With **environment variables**, you can have variables whose contents depend on the environment or stage you work in. Rulecube has these environments:

* **test**\
  This is the development environment where you create and maintain rulesets.
* **demo**\
  This is the quality assurance environment where testers and users test rulesets.
* **app**\
  This is the live environment where users work with rulesets.

And this is the correlated development process you usually follow for your rulesets:

1. You create and maintain your rulesets in the **test** environment.
2. When ready, you export your ruleset and import it into the **demo** environment.
3. The persons responsible for quality assurance test the ruleset in the **demo** environment.
4. You correct the issues they find in **test** and deploy them to **demo** until you solved all issues, and the ruleset is ready to go live.
5. You export your ruleset and import it into the **app** environment where users work with it.

### A variable with a different value for each environment

Now, let's assume that a ruleset calls an external API for financial data, and the corresponding URL varies per environment:

<table><thead><tr><th width="203">Environment</th><th>API URL</th></tr></thead><tbody><tr><td><strong>test</strong></td><td><code>dev.findata.com</code></td></tr><tr><td><strong>demo</strong></td><td><code>test.findata.com</code></td></tr><tr><td><strong>app</strong></td><td><code>api.findata.com</code></td></tr></tbody></table>

One solution to this is to create a constant for the URL and change the constant value each time you deploy your ruleset to a different environment. But this is cumbersome and error-prone. So it's much better to use an environment variable because you only have to set the environment-specific values for the same variable once. And when you deploy your ruleset, Rulecube automatically chooses the correct variable value for the environment it's running in.

For example, you create an environment variable named `FinDataURL` and assign it the appropriate values in each environment:

<table><thead><tr><th width="203">Environment</th><th>FinDataURL</th></tr></thead><tbody><tr><td><strong>test</strong></td><td><code>https://dev.findata.com</code></td></tr><tr><td><strong>demo</strong></td><td><code>https://test.findata.com</code></td></tr><tr><td><strong>app</strong></td><td><code>https://api.findata.com</code></td></tr></tbody></table>

Now, when you run in **test**, Rulecube automatically picks the `dev.findata.com` URL, and when you run in **app,** Rulecube selects the `api.findata.com` URL. Fully automated, without any intervention from your side.

## Procedure

Let's bring the example into practice:

### Step 1: Create the environment variable in test and use it in the ruleset&#x20;

1. If you're not in your Rulecube **test** environment, move over to **test**.

2. Create a ruleset named `EnvExample`.

3. Click **Variables** from the top menu.\
   ↳ The general **Environment variables** page opens.

4. Click **Add variable**.\
   ↳ Rulecube adds a new environment variable row.

5. In the **Name** field, enter `FinDataURL`.

6. In the **Value** field, enter `https://dev.findata.com`.

7. Click **Save**.

8. Now, open the ruleset where you want to use the environment variable.

9. Click **Environment variables** from the menu at the left.\
   ↳ The ruleset **Environment variables** page opens:\ <br>

   <div align="left"><figure><img src="/files/W22kiCQVuPBS3MdtenDj" alt=""><figcaption></figcaption></figure></div>

10. Select the **FinDataURL** checkbox.

11. Create a rule named `ShowURL` and set its **Expression** to:<br>

    <pre class="language-javascript" data-line-numbers><code class="lang-javascript">FinDataURL
    </code></pre>

    \
    ↳ This rule just returns the content of the environment variable, which is fine for illustrating how environment variables work, but in practice, a rule **Expression** like this is more realistic:<br>

    <pre class="language-javascript" data-line-numbers><code class="lang-javascript">Http.request(FinDataURL + "?region=europe").data.data
    </code></pre>

12. Click **Save**.

13. Click **Try it out**.

14. Click **Execute**.\
    ↳ The **Sandbox** output shows `"https://dev.findata.com"`.

### Step 2: Create the environment variable in demo

1. Move over to your **demo** environment.
2. Click **Variables** from the top menu.
3. Click **Add variable**.
4. In the **Name** field, enter `FinDataURL`.
5. In the **Value** field, enter `https://test.findata.com`.
6. Click **Save**.

### Step 3: Create the environment variable in app

1. Move over to your **app** environment.
2. Click **Variables** from the top menu.
3. Click **Add variable**.
4. In the **Name** field, enter `FinDataURL`.
5. In the **Value** field, enter `https://api.findata.com`.
6. Click **Save**.

### Step 4: Deploy your ruleset

1. Move back to your **test** environment.
2. Open the `EnvExample` ruleset.
3. Click **Export**.\
   ↳ The **Export** pop-up opens.
4. Click **OK**.\
   ↳ Rulecube exports the ruleset as a JSON file into the default download folder on your workstation.
5. Move over to your **demo** environment.
6. Click **Import**.\
   ↳ The **Import ruleset** pop-up opens.
7. Open your file manager and navigate to your default download folder.
8. Drag the exported ruleset JSON file and drop it on the **Upload (or drag) ruleset data file** section of the **Import ruleset** pop-up.
9. Click **Upload**.\
   ↳ Rulecube imports the ruleset and shows the **General settings** page for the ruleset.
10. Click **Try it out**.
11. Click **Execute**.\
    ↳ The **Sandbox** output now shows `"https://test.findata.com"` as the value of the `FinDataURL` environment variable.

And you can do the same deployment steps for your **app** environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rulecube.com/v2.5/how-to-guides/work-with-environment-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
