github.com/szkiba/xk6-dotenv@v0.2.0/README.md (about)

     1  # xk6-dotenv
     2  
     3  A k6 extension that loads env vars from a .env file.
     4  
     5  This extension follow the [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use) for managing multiple environments (i.e. development, test, production). The actual environment name came from an env variable named `K6_ENV`. Setting this to `false` value disable the convention mentoined above and no .env file will be loaded automatically.
     6  
     7  | Hierarchy Priority | Filename                 | K6_ENV                 | Should I `.gitignore`it? | Notes                                                        |
     8  | ------------------ | ------------------------ | ---------------------- | ------------------------ | ------------------------------------------------------------ |
     9  | 1st (highest)      | `.env.development.local` | development            | Yes!                     | Local overrides of environment-specific settings.            |
    10  | 1st                | `.env.test.local`        | test                   | Yes!                     | Local overrides of environment-specific settings.            |
    11  | 1st                | `.env.production.local`  | production             | Yes!                     | Local overrides of environment-specific settings.            |
    12  | 2nd                | `.env.local`             | (any _expect_ `false`) | Definitely.              | Local overrides. This file is loaded for all environments _except_ `test`. |
    13  | 3rd                | `.env.development`       | development            | No.                      | Shared environment-specific settings                         |
    14  | 3rd                | `.env.test`              | test                   | No.                      | Shared environment-specific settings                         |
    15  | 3rd                | `.env.production`        | production             | No.                      | Shared environment-specific settings                         |
    16  | Last               | `.env`                   | (any _expect_ `false`) | Depends                  | The Original                                                 |
    17  
    18  ## Usage
    19  
    20  The `.env` files are loaded automatically when starting k6. To use it, simply create the appropriate `.env` file (see table above) and set (optional) the `K6_ENV` environment variable.
    21  
    22  For the most convenient use, create a file called `.env.local` and write the environment variables you want to set in it. One variable per line, in `name=value` form.
    23  
    24  ```sh
    25  SOME_ENV_VAR=somevalue
    26  ```
    27  
    28  If you want to be really fancy with your env file you can do comments and exports:
    29  
    30  ```sh
    31  # I am a comment and that is OK
    32  SOME_VAR=someval
    33  FOO=BAR # comments at line end are OK too
    34  export BAR=BAZ
    35  ```
    36  
    37  ## Download
    38  
    39  You can download pre-built k6 binaries from [Releases](https://github.com/szkiba/xk6-dotenv/releases/) page. Check [Packages](https://github.com/szkiba/xk6-dotenv/pkgs/container/xk6-dotenv) page for pre-built k6 Docker images.
    40  
    41  ## Build
    42  
    43  The [xk6](https://github.com/grafana/xk6) build tool can be used to build a k6 that will include xk6-faker extension:
    44  
    45  ```bash
    46  $ xk6 build --with github.com/szkiba/xk6-dotenv@latest
    47  ```
    48  
    49  For more build options and how to use xk6, check out the [xk6 documentation](https://github.com/grafana/xk6).
    50