Menu
Grafana Cloud

Cloud environment variables

Environment Variables are key-value pairs that you configure at the organization level.

The cloud service encrypts all values before storing them in our database, and they remain encrypted until needed for a test run. If you reference a variable in a test script, the cloud service inserts the value of the variable on the server that runs the test.

You can use Environment Variables to store sensitive (and non-sensitive) information that you want to reference in your test-scripts. Managing environment variables in one central place brings the following benefits:

  • Reduced data exposure
  • An easier way to re-use and change values across different test scripts.

Note

Changes to an environment variable don’t apply to test runs that have already started.

Manage environment variables

Only owners and admins can create, modify, and delete environment variables. If you have appropriate permission, you can manage environment variables with these steps:

  1. Go to Settings > Environment variables.

Environment variables list

Rules for environment variable names

The following restrictions apply to environment variable names:

  • Names can contain only alphanumeric characters ([a-z], [A-Z], [0-9]) and underscores (_). Spaces are not allowed.
  • Names must not start with the K6_CLOUD prefix.
  • Names must not start with a number.
  • Names are case insensitive.
  • Names must be unique.

Declare a new environment variable

  1. Give your Environment Variable a name, then enter the respective Value.
  2. Optionally, add a brief description.
  3. Select Submit.

Environment variables dialog

Access environment variables

If you create an Environment Variable on k6 Cloud, you can reference it in your k6 script through the __ENV variable, as you would with other k6 Environment Variables

JavaScript
import http from 'k6/http';
import { sleep } from 'k6';

export default function () {
  const params = {
    headers: { Authorization: __ENV.AUTH_TOKEN },
  };
  const res = http.get(__ENV.SERVICE_URL, params);
  sleep(1);
}

Warning

The current environment variables implementation doesn’t prevent printing values to the log (or restrict exposing a variable any other way). You should avoid printing sensitive data to the log intentionally.

Order of precedence

When starting tests with k6 cloud, environment variables set via CLI flag --env and environment variables set in the cloud are combined and used together to run the test. If an environment variable is both set via CLI and declared in the cloud, the value set via the CLI will be applied instead of the value set in the cloud.

Warning

Environment variables set via CLI flag will still be stored in the archive as plain data.