Guides

Set environment variables

Add or change the environment variables of an app and apply them.

Each app has its own environment variables. This guide adds and changes them after the first deploy. A saved change takes effect with the next deploy of the app. Environment Variables explains detection, secrets and generations.

Before you start

  • A deployed app. The examples use the app copperfox.

Steps

Add or change variables

  1. Open the app and select the Environment tab.
  2. Edit Key and Value in the table, or select Bulk edit and paste one variable per line. Keys and values are separated by =. Lines that start with # are ignored.
  3. Save. All changes are saved together. If one variable is invalid, nothing is saved and the errors are listed.
lly env copperfox set LOG_LEVEL=debug FEATURE_X=on

To load a whole .env file:

lly env copperfox push .env.production

Apply the change

The running app keeps the values it was started with. Redeploy it to apply the new ones.

After saving, the console confirms that the variables apply on the next deployment and offers Redeploy. The Environment tab shows whether the saved values are live or wait for the next deploy.

lly redeploy copperfox

Check that it worked

lly env copperfox
  Environment Variables
  Key        Value
  LOG_LEVEL  debug
  API_TOKEN  ••••••  · src/api.ts

Secret values are masked. Detected variables show the file they were found in.

Secrets

A variable is treated as a secret if its name contains SECRET, PASSWORD, TOKEN, KEY, CREDENTIAL or PRIVATE, or if it is a database URL. A secret value is not shown again after saving. To change a secret, remove it and add it again:

lly env copperfox unset API_TOKEN
lly env copperfox set API_TOKEN=<new value>
lly redeploy copperfox

If it does not work

What you seeCauseFix
The app still uses the old valueThe change is saved but not appliedRedeploy the app
lly env set exits with code 2The variable is an existing secretunset it, then set it again
lly env get exits with code 2The variable is a secretSecret values cannot be read
Exit code 4The variable does not existCheck the name with lly env copperfox
Your app does not find PORTLILY does not set PORTSet the port the app listens on as a service port. See Expose a port

More messages and their fixes: Troubleshooting.

Use an agent

Set these environment variables on my LILY app "copperfox": LOG_LEVEL=debug.
Run `lly env copperfox set LOG_LEVEL=debug`, then `lly redeploy copperfox`.
Never print secret values. If a variable is an existing secret, tell me instead of changing it.

Next steps

On this page